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

dixitchopra's avatar

Change Base URL after Log In

Here is the URL

http://localhost:8000/login

Once I log in, I want to change base URL from

http://localhost:8000 to http://localhost:8000/app/

This is how my URLs should look. The thing is I have already written a href='/settings' and Request::is('settings') and don't want to rewrite the code again to match new URL structure.

I don't want to go to each link and append 'app/' now.

http://localhost:8000/app/analytics
http://localhost:8000/app/settings
0 likes
7 replies
sj's avatar

Are you using Laravel 5 Auth system?

sj's avatar

in your http/controller/auth/AuthController.php add this

    /**
     * Set the redirect to property after the user has been logged in.
     */
    protected $redirectTo = '/app';

dixitchopra's avatar

The problem is, I have written code everywhere like this

href="{{ URL::to('/bills/yearly-visits') }}

and would like to change each and every URL to

href="{{ URL::to('/app//bills/yearly-visits') }}

I know, I can do like the above one but this is not the right way. Can this be done in a better way?

bobbybouwmann's avatar

There is a reason we just named routes ;)

Route::get('/app/bills/yearly-visits', ['as' => 'bills.yearly-visits', 'uses' => 'BillsController@yearly-visits']);

href="{{ URL::route('bills.yearly-visits') }}

Now when you change the url you won't have to change it in your code! I would advise you to make this change in your code, it will take some time, but then you can use any url you want ;)

dixitchopra's avatar

I am also changing URL based on the url. I am using get request and URL can be changed to

href="{{ URL::to('/bills/yearly-visits'?search=Matt) }}

The URL has many such parameters. I am looking to append '/app in $path variable.

bobbybouwmann's avatar
Level 88

Like I said before, it's wiser to update your routes to use a route name and then you can append any kind of variables to your url.

URL::route('bills.yearly-visits', ['search' => 'Matt']);

Just read the documentation on it ;)

Please or to participate in this conversation.