我需要检查一些路线的域名。然后在检查之后,我需要将域名https://two.com重定向到在laravel中带有middleware的https://one.com。
例如:
路由:
Route::get('/', ['as' => 'index', 'uses' => 'IndexController@index']);
Route::get('termsAndCondition', ['as' => 'termsAndCondition', 'uses' => 'IndexController@termsAndCondition']);
Route::get('aboutUs', ['as' => 'aboutUs', 'uses' => 'IndexController@aboutUs']);
Route::get('privacy', ['as' => 'privacy', 'uses' => 'IndexController@privacy']);我需要检查域名的aboutUs和privacy。
如果域名为https://two.com/aboutUs或https://two.com/privacy,请重定向至https://one.com/aboutUs或https://one.com/privacy。
我需要和中间件核对一下。
谢谢。
发布于 2018-01-07 18:40:47
您可以在中间件中执行以下操作:
if (request()->getHttpHost() === 'two.com' && in_array(request()->path(), ['aboutUs', 'privacy'])) {
return redirect('https://one.com/' . request()->path());
}发布于 2018-01-07 18:38:51
您可以使用segment()帮助程序检查url段,如下所示:
if(Request::segment(1)==='aboutus')
{
return redirect(route('your other route');
}
if(Request::segment(1)==='privacy')
{
return redirect(route('your other route');
}您可以在您的中间件中添加该检查,segment()需要一个整数参数,例如上面的1将检查域名后的第一个通配符。
https://stackoverflow.com/questions/48136290
复制相似问题