2014-02-12 64 views
15

当我尝试这个laravel尾随斜线重定向到本地主机

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

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

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

它重定向我

http://localhost/users/login/ 

任何想法,为什么?

这是我的htaccess文件

<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> 

回答

19

更改您的代码如下:

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] 
+0

我尝试,但现在它重定向到http://本地主机/ C:/ XAMPP/htdocs/testlaravel/public/users/login – user3213240

+0

好吧我添加了RewriteBase/Testlaravel/public /,现在它工作thx :) – user3213240

+1

对我来说,行:** RewriteBase/Testlaravel/**工作,因为我没有使用公共文件夹并摆脱它。谢谢。 –

1

如果上述方法不工作,然后用 缓存清除浏览器历史记录,然后再试一次。

+1

可以是评论。 – Robert

0

我刚添加到我的.htaccess文件,它工作正常!

RewriteCond %{REQUEST_URI} !^ 
0

我的项目目录是

C:\ WAMP \ WWW \ laravel_apps \ LI3 \

,改变了公众的.htaccess文件夹内以下

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

    RewriteEngine On 

    # Redirect Trailing Slashes If Not A Folder... 
    RewriteCond %{REQUEST_FILENAME} !-d 
    RewriteRule ^(.*)/$ /laravel_apps/li3/public/$1 [L,R=301] 

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

    # Handle Authorization Header 
    RewriteCond %{HTTP:Authorization} . 
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}] 
</IfModule> 

我只是替换为

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

RewriteRule ^(.*)/$ /laravel_apps/li3/public/$1 [L,R=301] 

现在,如果你把一个斜线在URL的末端会重定向到同一页面