Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

SuperSephy's avatar

Laravel as subdirectory through proxy

This may sound a bit tricky, but please bear with me. My organization built a service using the laravel 5.1 framework and it's ready to deploy. Our issue is that our convention is to add services to our domain through a named subdirectory. So if our domain is https://www.domainName.com we might have our proxy direct to rackspace services using https://www.domainName.com/rsp/. To this end we use nginx to detect the rsp and direct to the rackspace IP. Now, we just spun up a new ubuntu server hosting our laravel project and lets say we want to follow our convention with something like domainName.com/lvl/ - how can we set this up? We have the proxy directing correctly and we can access something like domainName.com/lvl/page, but all the Laravel links created through the route helper: i.e.

page.blade.php

route('lists',['path'=>'list','archived'=>'y']

on that page are generating links without the lvl directory: i.e. domainName.com/lists?path=lists,archived=y

Technically, I've been able to patch it using

<?php URL::forceRootUrl('https://www.domainName.com/lvl')

at the top of every blade... but this is breaking some of the resources. Additionally, none of my .htaccess edits have seemed to have any effect either. Are there any enthusiasts that might be able to lend a hand? Any thoughts appreciated!


Edit: I should note that we're trying to avoid changing to a sub-domain due to our SSL cert and user experience consistency issues.

0 likes
3 replies
d3xt3r's avatar

For routes you can take care of this by moving all your routes inside a group

    Route::group(['prefix'=>'lvl'], function() {
        ... Route definitions
    });

Hopefully, you use cdn for static files or else there you will have to use prefix in blade as well.

    {{ asset('lvl/css/whatever.css') }}

Please or to participate in this conversation.