如何检查 Laravel 中的某些路由的域?

myS*_*Sun 3 laravel laravel-5

我需要检查某些路由的域。然后检查后,我需要将域名重定向https://two.com到laravel 中的https://one.comwith 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']);
Run Code Online (Sandbox Code Playgroud)

我需要检查aboutUsprivacy域名。

如果域名是https://two.com/aboutUshttps://two.com/privacy重定向到https://one.com/aboutUshttps://one.com/privacy.

我需要检查中间件。

谢谢。

Ale*_*nin 6

您可以在中间件中执行以下操作:

if (request()->getHttpHost() === 'two.com' && in_array(request()->path(), ['aboutUs', 'privacy'])) {
    return redirect('https://one.com/' . request()->path());
}
Run Code Online (Sandbox Code Playgroud)