Laravel Trailing Slashes重定向到公共网址

时间:2018-05-09 11:18:46

标签: php laravel .htaccess

在我与Laravel一起开发的项目中,我遇到了一个奇怪的问题。

如果我尝试转到网址http://localhost/admin/page,laravel会将我重定向到http://localhost/admin/page,但如果我尝试转到http://localhost/admin/page/,请使用尾随斜杠,我会重定向到{ {3}}

这是项目根目录上的.htaccess:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*)$ public/$1 [L]
</IfModule>

这是我公共文件夹上的.htaccess:

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

    RewriteEngine On

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

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

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

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d

</IfModule>

即使我转到http://localhost/public/admin/page,我也想重定向到http://localhost/admin/page。我怎么能解决?

1 个答案:

答案 0 :(得分:0)

好的,经过一些调试我发现实际配置已经正常工作了。 Google Chrome缓存存在问题。为了将来参考,只需使用我的配置,清除浏览器缓存并重试。