Laravel 路由检查多个字符串

Sou*_*ose 8 php laravel laravel-routing laravel-5

我想要重定向(301)一些包含以下内容的路线 -

page=1(查询字符串)或 index.php?&(查询字符串)

我已将路线添加为 -

Route::get('/{any_url}', 'UsersController@processRedirect')->where('any_url', '(.*)index\.php(.*)|(.*)page=1(.*)|(.*)|?&(.*)');
Run Code Online (Sandbox Code Playgroud)

当我在https://regex101.com/ 中检查时,它正在工作,但在我的应用程序中它无法工作。

可能是什么问题?

我已通过 MiddleWare 完成此操作,但我不想检查所有网址。

有没有其他方法可以实现这一目标?

jge*_*ner 4

因此,技巧不是在路由中执行此操作,而是创建一个捕获所有路由的全局捕获所有路由,然后您可以在控制器中对路径或查询字符串进行任何处理。这使您的路由保持干净且易于使用,并允许更强大地处理查询字符串和路径或基本 URL。请务必删除要使用此捕获所有路由处理的路由。

路线/web.php

//make this last route to catch
Route::any('/{any}', "ProcessRequestController@handler")->where("any", ".*");
Run Code Online (Sandbox Code Playgroud)

应用程序/Http/Controllers/ProcessController.php

namespace App\Http\Controllers;

use Illuminate\Http\Request;


class ProcessRequestController extends Controller{

    public function handler(Request $request){
        //from here you can now access each section of the route a little more conviently.
        $request->path();
        if($request->has('page')){

        }
    }
}
Run Code Online (Sandbox Code Playgroud)