我希望能够在我的应用程序中为不同的域使用不同的路由。我想采取不同的行动,具体取决于域名是否为Laravel路线组匹配整个域
- 我自己的域名例如
mysite.com/something
- 我的域的子域例如
subdomain.mysite.com/something
- 任何其他域例如
anotherdomain.com
我处理这个问题是这样的:
// Match my own domain
Route::group(['domain' => 'mysite.com'], function()
{
Route::any('/', function()
{
return 'My own domain';
});
});
// Match a subdomain of my domain
Route::group(['domain' => '{subdomain}.mysite.com'], function()
{
Route::any('/', function($subdomain)
{
return 'Subdomain ' . $subdomain;
});
});
// Match any other domains
Route::group(['domain' => '{domain}'], function()
{
Route::any('/', function()
{
return 'Full domain ';// . $domain;
});
});
前两组正常工作。如预期的那样,访问mysite.com
显示My own domain
并访问subdomain.mysite.com
显示Subdomain subdomain
。然而,当我与anotherdomain.com
参观(我有这样的设置为我的虚拟主机文件的别名,以及它指向回送IP在我的hosts文件),我得到一个NotFoundHttpException
:
/var/www/portfolio/vendor/laravel/framework/src/Illuminate/Routing/RouteCollection.php
代码:
$others = $this->checkForAlternateVerbs($request);
if (count($others) > 0)
{
return $this->getOtherMethodsRoute($request, $others);
}
throw new NotFoundHttpException;
}
有没有一种方法可以匹配任何不属于我的域或域的子域的域?我需要能够访问该域名,以后也可以使用它,就像我使用$subdomain
一样。
感谢, 乔纳森
无论谁投下了票,你会介意与我们分享原因吗?这是正确使用本网站的方式。 – 2015-02-16 09:10:48
仔细阅读问题并回答您通过本文解决问题中描述的问题? – 2015-06-26 04:56:31