我有2套路线,域名保存在HOST
的env文件中,第一组可以通过example.com
加入,第二组应该使用somesubdomain.example.com
,这项工作,问题是当我不能从subdomains route
重定向到root routes
,subdomain
坚持所以root route
不会进入,我尝试使用named routes
但它重定向到localhost/dashboard
xampp仪表板。
//root routes
Route::namespace('Main')->domain(env('HOST'))->group(function(){
Route::get('/','Home\HomeController@getMain')->name('inicio');//i have tried to name the route but this just redirect to localhost/dashboard
});
//subdomain routes
Route::namespace('Stores')->domain('{subdomain}.'.env('HOST'))->group(function(){
Route::get('/',function(){
return redirect()->route('inicio');
});
});
两条路线都工作,如果不是redirect
我做return 'foo';
它显示foo时它有子域,并返回一个视图,当它没有。
如何删除子域并重定向到路由?
我认为解决方案可能是重定向到没有任何参数且没有绝对URL的命名路由,例如:
//root routes
Route::namespace('Main')->domain(env('HOST'))->group(function(){
Route::get('/','Home\HomeController@getMain')->name('inicio');
});
//subdomain routes
Route::namespace('Stores')->domain('{subdomain}.'.env('HOST'))->group(function(){
Route::get('/',function(){
return redirect()->to(route('inicio', [], false);
});
});
唯一的变化是重定向应该看起来像:
return redirect()->to(route('inicio', [], false);
第一个参数是命名路由,第二个参数包括任何参数(在本例中为none),第三个参数指定URL是否应该是绝对的。
我手边没有环境来测试这个,但希望这是一个适合你的解决方案。