如何在 laravel 中检查某些路由的域?
How to check domain in laravel for some routes?
我需要检查一些路由的域。然后在检查之后,我需要将域 https://two.com
重定向到 https://one.com
并在 laravel.
中使用 middleware
例如:
路线:
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
.
我需要检查中间件。
谢谢。
您可以使用 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 将检查域名后的第一个通配符。
你可以在中间件中做这样的事情:
if (request()->getHttpHost() === 'two.com' && in_array(request()->path(), ['aboutUs', 'privacy'])) {
return redirect('https://one.com/' . request()->path());
}
我需要检查一些路由的域。然后在检查之后,我需要将域 https://two.com
重定向到 https://one.com
并在 laravel.
middleware
例如:
路线:
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
.
我需要检查中间件。
谢谢。
您可以使用 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 将检查域名后的第一个通配符。
你可以在中间件中做这样的事情:
if (request()->getHttpHost() === 'two.com' && in_array(request()->path(), ['aboutUs', 'privacy'])) {
return redirect('https://one.com/' . request()->path());
}