Laravel 5:带有尾部斜杠的URL被重定向到localhost

时间:2015-09-27 20:20:10

标签: php .htaccess laravel-5

我可以使用http://localhost/rnd/public/coeg-admin访问我的网址,但如果我访问http://localhost/rnd/public/coeg-admin/,则会将其重定向到http://localhost/coeg-admin

我只关注laravel trailing Slashes redirect to localhostURL with trailing slashes gets redirected to localhost in laravel 5

但它没有按预期工作,这是我的.htaccess

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

    RewriteEngine On

    # Set base URL
    # RewriteBase /rnd/public/
    # RewriteRule ^(.*)/$ /$1 [L,R=301]
    # RewriteCond %{REQUEST_URI} !^

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

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

这是我的apache2.conf

<Directory "/var/www/html/rnd/public">
        Options Indexes FollowSymLinks
        #AllowOverride None
        AllowOverride All
        Require all granted
</Directory>

<Directory "/var/www/html">
        Options Indexes FollowSymLinks
        AllowOverride All
        Require all granted
</Directory>

如何,我可以在末尾将带有斜杠的url重定向到url而不用斜杠?

谢谢,任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

我做的最简单的方法是从公共/ .htaccess

中删除RewriteRule ^(.*)/$ /$1 [L,R=301] 不要忘记清除缓存,因为Chrome重定向缓存也保存在浏览器中