【问题标题】:Redirect to index.php and remove trailing slash .htaccess重定向到 index.php 并删除尾部斜杠 .htaccess
【发布时间】:2019-03-28 01:04:11
【问题描述】:

这里似乎有很多这样的问题,但找不到适合我当前代码的答案:

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^ public/index.php [QSA,L]

这会将所有内容重定向到public/index.php,这可以正常工作,但我想去掉尾部斜杠,以便example.com/foo/ 变为example.com/foo

【问题讨论】:

    标签: apache .htaccess mod-rewrite server webserver


    【解决方案1】:

    您可以在当前规则之前插入一个尾部斜杠删除代码

    RewriteEngine On
    
    ## Unless directory, remove trailing slash
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_URI} ^(.+)/+$
    RewriteRule ^ %1 [R=301,NE,L]
    
    ## forward all requests to public/index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^ public/index.php [L]
    

    【讨论】:

    猜你喜欢
    • 2012-07-01
    • 2016-10-29
    • 1970-01-01
    • 1970-01-01
    • 2015-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多