【问题标题】:Ignore trailing slash from RewriteCond and RewriteRule忽略来自 RewriteCond 和 RewriteRule 的尾部斜杠
【发布时间】:2017-02-02 17:05:09
【问题描述】:

我的 htaccess 文件中有以下内容:

RewriteCond %{REQUEST_METHOD} GET
RewriteCond %{DOCUMENT_ROOT}/cached/%{REQUEST_URI}\.html -f
RewriteRule .* cached/%{REQUEST_URI}\.html [L]

我有一个网址 blah.com/a/

我有一个缓存的文件/a.html

如何告诉我的 htaccess 忽略尾部斜杠,以便查找并显示 a.html 而不是 a/.html

注意:从 URL 中删除斜线不是一个选项,因为 URL 模式已经设置。

【问题讨论】:

    标签: apache .htaccess mod-rewrite


    【解决方案1】:

    这是因为 %{REQUEST_URI} 将尾部斜杠添加到映射到无效 uri /file/.html 的目标,要解决此问题,您需要改用反向引用。

    RewriteCond %{DOCUMENT_ROOT}/cached/$1.html -f
    RewriteRule ^(.*?)/?$ /cached/$1.html [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-09-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多