I would like to be able to use different routes in my application for different domains. I would like to act differently depending on whether the domain is
- My own domain, for example.
mysite.com/something - A subdomain of my domain, for example.
subdomain.mysite.com/something - Any other domain, for example.
anotherdomain.com
I approached such a problem:
Route::group(['domain' => 'mysite.com'], function()
{
Route::any('/', function()
{
return 'My own domain';
});
});
Route::group(['domain' => '{subdomain}.mysite.com'], function()
{
Route::any('/', function($subdomain)
{
return 'Subdomain ' . $subdomain;
});
});
Route::group(['domain' => '{domain}'], function()
{
Route::any('/', function()
{
return 'Full domain ';
});
});
The first two groups work fine. Visits mysite.comdisplays My own domainand visits are subdomain.mysite.comdisplayed Subdomain subdomainas expected. However, when I visit using anotherdomain.com(I have it configured as an alias in my vhost file and also points to the loopback IP address in my hosts file), I get NotFoundHttpException:
/var/www/portfolio/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php
the code:
$others = $this->checkForAlternateVerbs($request);
if (count($others) > 0)
{
return $this->getOtherMethodsRoute($request, $others);
}
throw new NotFoundHttpException;
}
, , ? , - , , $subdomain.
,