如何让Laravel 5.3创建带有斜线的路由URL?Laravel:我如何让路线路线返回带有斜线的路线?
路线被定义为
Route::get('/home/', ['as' => 'home', 'uses' => '[email protected]']);
然后创建与在视图中的路线辅助函数的网址:
{{ route('home') }}
这产生http://localhost:8000/home
代替http://localhost:8000/home/
。
此问题与Laravel - append a trailing slash in routes非常相似,但该问题也没有答案,在我看来,我的描述更短。
编辑: 从文档的两种可能的命名方法不有所作为:
Route::get('/home/', ['as' => 'home', 'uses' => '[email protected]']);
Route::get('/home/', '[email protected]')->name('home');
当你使用尾部斜线访问它时会发生什么? afaik它会重定向到别的地方。其解决方案之一是[这么回答](http://stackoverflow.com/a/21735548/4648586) –
只要Web服务器不重定向laravel将响应请求。 – tback
它与['.htaccess'](https://github.com/laravel/laravel/blob/master/public/.htaccess#L10)有关。正如它在[这个问题](http://stackoverflow.com/questions/34441338/laravel-5-bad-behaviour-while-removing-trailing-slash)中讨论的,你必须在公共目录中编辑你的'.htaccess'。虽然... [在某些讨论中](https://github.com/laravel/framework/issues/58#issuecomment-12367008) –