gpt4 book ai didi

laravel - 如何在 laravel 中检查域中的某些路由?

转载 作者:行者123 更新时间:2023-12-02 20:32:54 24 4
gpt4 key购买 nike

我需要检查一些路由的域。然后在检查之后,我需要使用 laravel 中的 middleware 将域 https://two.com 重定向到 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']);

我需要检查 aboutUsprivacy 域名。

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

我需要检查中间件。

谢谢。

最佳答案

你可以在中间件中做这样的事情:

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

关于laravel - 如何在 laravel 中检查域中的某些路由?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48136290/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com