【问题标题】:Append '/' after URL using .htaccess使用 .htaccess 在 URL 后附加“/”
【发布时间】:2014-09-21 23:04:50
【问题描述】:
<Directory /var/www/html/>
        Options +SymLinksIfOwnerMatch
        RewriteEngine on
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ index.php?url=$1 [L]
</Directory>

如何修改上述 .htaccess 规则以在 URL 后添加 / 而不会破坏现有的 RewriteRule?

我尝试简单地附加:RewriteRule ^(.*)([^/])$ http://%{HTTP_HOST}/$1$2/ [L,R=301],但这不起作用。

【问题讨论】:

    标签: apache .htaccess mod-rewrite url-rewriting trailing-slash


    【解决方案1】:

    只需检查 URI 是否以 / 结尾,如果不是,则在 URI 中添加一个。

    RewriteCond %{REQUEST_URI} !(/$|\.) 
    RewriteRule (.*) %{REQUEST_URI}/ [R=301,L] 
    

    【讨论】:

      猜你喜欢
      • 2011-12-06
      • 1970-01-01
      • 2019-05-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-06-10
      • 2012-11-19
      相关资源
      最近更新 更多