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

awcode's avatar

Laravel route issue with domain and folder

My development environment for laravel runs in a subfolder, which had been working fine until added a second domain into the mix.

Route::get('/',  'Web\HomeController@index')->name('web.index');

With this normal setup would get the correct http://example.com/subfolder/public from the command below.

echo route('web.index');

But now, I haved added domain grouping to run separate functions for a secondary domain name.

Route::group(['domain' => 'example.com'], function(){
  Route::get('/',  'Web\HomeController@index')->name('web.index');
});
Route::group(['domain' => 'another.com'], function(){
  Route::get('/',  'Web\OtherController@index')->name('other.index');
});
Now the same echo route returns http://example.com/ although a call of {{ URL::to('/') }} will return http://example.com/subfolder/public

Pages do work fine and load on the correct links, it is just the output of the route() command that is losing the prefix.

Tried passing a route prefix to the group but that just means I need to visit http://example.com/subfolder/public/subfolder/public to get the homepage

How can I restore the prefix when generating route links, without adding a duplicate prefix when checking the URL for route matches?

0 likes
0 replies

Please or to participate in this conversation.