[英]Laravel subdomain route - NotFoundHttpException
I'm working on API in my Laravel project, and have problem with setting up subdomain (Ubuntu). 我正在使用我的Laravel项目中的API,并且在设置子域(Ubuntu)时遇到问题。
I set up Virtualhost
, Routing
, enabled vhost_alias
我设置了
Virtualhost
, Routing
,启用了vhost_alias
VirtualHost: 虚拟主机:
<VirtualHost *:80>
ServerName domain.io
ServerAlias domain.io
DocumentRoot mypath
<Directory mypath>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
<VirtualHost *:80>
ServerName api.domain.io
ServerAlias api.domain.io
DocumentRoot mypath
<Directory mypath>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
My route: 我的路线:
Route::group(['domain' => 'api'.env('APP_HOST')], function() {
Route::get('test', function() {
return 'test';
});
});
Url http://api.domain.io/
redirect to main domain domain.io
. Url
http://api.domain.io/
重定向到主域domain.io
。 When I visit my route http://api.happs.io/test
I get error (like there would not be that route): 当我访问我的路线
http://api.happs.io/test
我得到错误(就像没有那条路线):
NotFoundHttpException in RouteCollection.php line 161:
RouteCollection.php第161行中的NotFoundHttpException:
Add *.
添加
*.
before your domain name on ServerAlias
and make sure you have a wildcard CNAME. 在
ServerAlias
上的域名之前,并确保您有一个通配符CNAME。
<VirtualHost *:80>
ServerName domain.io
ServerAlias *.domain.io
DocumentRoot mypath
<Directory mypath>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Try this, put the domain and subdomain in the NameServer: 试试这个,把域和子域放在NameServer中:
<VirtualHost *:80>
ServerName domain.io api.domain.io
DocumentRoot mypath
<Directory mypath>
AllowOverride All
Order allow,deny
Allow from all
</Directory>
</VirtualHost>
Your hosts
file is correct. 您的
hosts
文件是正确的。 The issue is your env('APP_HOST')
is a static value but it needs to be dynamic with your setup. 问题是你的
env('APP_HOST')
是一个静态值,但它需要你的设置是动态的。
An option, and likely the easiest approach (it's the one I use too), is to just create a route for the sub domain manually. 一个选项,也可能是最简单的方法(也是我使用的方法),就是手动为子域创建路由。
Route::group(['domain' => 'api.happs'], function() {
// Do something
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.