Laravel-使用Redirect :: route()添加结尾斜杠 [英] Laravel - Add trailing slash with Redirect::route()
问题描述
在Laravel中使用Redirect::route()
后,我试图在URL末尾添加斜杠.
我尝试了很多例子,但找不到答案.
I'm trying to add a slash to the end of the URL after I use Redirect::route()
with Laravel.
I've tried numerous examples but couldnt find an answer.
这是我到目前为止所拥有的:
This is what I have so far:
routes.php
:
Route::get('/', function() {
return Redirect::route('login');
});
Route::get('/login/', array(
'as' => 'login',
'uses' => 'Controller@login'
));
Controller.php
:
public function login()
{
return 'Login page';
}
当我转到htdocs/laravel_project/
时,我被重定向到htdocs/laravel_project/login
,但我希望它成为htdocs/laravel_project/login/
,我想在URL的末尾添加斜杠.如果我确实在URL上手动输入了斜杠,那么它就会满足我的要求.
When I go to htdocs/laravel_project/
, I get redirected to htdocs/laravel_project/login
but I want it to be htdocs/laravel_project/login/
I want to add that slash to the end of the URL. If I do manually enter the slash at the URL it does what I want.
推荐答案
You are calling Redirect::route
which translates to:
重定向到网址( with ).
请注意,Laravel将自动删除生成的URL的斜杠.
Notice that Laravel will automatically remove the trailing slash of generated URL.
因此,没有进一步/深入的研究,最快的方法将是:
So, without further/deeper investigation, the fastest method would be:
return Redirect::to(URL::route('login') . '/');
这篇关于Laravel-使用Redirect :: route()添加结尾斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!