laravel尾随斜线重定向到本地主机 [英] laravel trailing Slashes redirect to localhost

查看:288
本文介绍了laravel尾随斜线重定向到本地主机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我尝试这种

 的http://本地主机/ Testlaravel /公/用户/登录
 

它的工作原理。但是,当我尝试

 的http://本地主机/ Testlaravel /公/用户/登录/
 

它重定向我

 的http://本地主机/用户/登录/
 

任何想法,为什么?

这是我的htaccess的文件

 < IfModule mod_rewrite.c>
    < IfModule mod_negotiation.c>
        选项​​-MultiViews
    < / IfModule>

    RewriteEngine叙述上

    #重定向结尾的斜杠...
    重写规则^(。*)/ $ / $ 1 [L,R = 301]

    #拉手前端控制器...
    的RewriteCond%{} REQUEST_FILENAME!-d
    的RewriteCond%{} REQUEST_FILENAME!-f
    重写规则^的index.php [L]
< / IfModule>
 

解决方案

更​​改code到这一点:

 选项-MultiViews
RewriteEngine叙述上
的RewriteBase / Testlaravel /公/

#重定向结尾的斜杠...
重写规则^(。*)/ $ $ 1 [L,R = 301]

#拉手前端控制器...
的RewriteCond%{} REQUEST_FILENAME!-d
的RewriteCond%{} REQUEST_FILENAME!-f
重写规则^的index.php [L]
 

When I try this

http://localhost/Testlaravel/public/users/login

it works. But when I try

http://localhost/Testlaravel/public/users/login/ 

it redirects me to

http://localhost/users/login/

Any idea why?

This my htaccess file

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

解决方案

Change your code to this:

Options -MultiViews
RewriteEngine On
RewriteBase /Testlaravel/public/

# Redirect Trailing Slashes...
RewriteRule ^(.*)/$ $1 [L,R=301]

# Handle Front Controller...
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [L]

这篇关于laravel尾随斜线重定向到本地主机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆