Laravel 5 中具有无限数量段的路由

nku*_*hta 0 php laravel laravel-5

我想将以“/app/”段开头的任何链接路由到一个控制器操作。网址示例:

http://localhost/app/
http://localhost/app/something
http://localhost/app/something/something2
http://localhost/app/something/something2/..../somethingN
Run Code Online (Sandbox Code Playgroud)

我需要将这些所有 url 路由到一个控制器操作。如何在 Laravel 5 中做到这一点?

geo*_*ldc 5

您可以使用正则表达式约束将所有参数集中到 1 个变量中

Route::get('app/{parameters?}', 'HomeController@app')->where('parameters', '.*');

然后 $parameters 变量将填充 app 之后的任何内容(例如“something/something2”、“something/something2/something3”等)。然后您可以根据需要解析它。