【问题标题】:Strange behavior RewriteCond on Apache 2.2Apache 2.2 上的奇怪行为 RewriteCond
【发布时间】:2010-09-30 18:20:27
【问题描述】:

工作 .htaccess 配置:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} ^thumbs/(.*)$
RewriteRule ^(.+)$ /index.php [L,QSA]

对 /thumbs/ 文件夹的所有 404 查询不必被 /index.php 脚本捕获。为什么顶部 .htaccess 配置有效而底部配置无效?

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-l
RewriteCond %{REQUEST_URI} !^/thumbs/(.*)$
RewriteRule ^(.+)$ /index.php [L,QSA]

Apache 2.2.9,Debian

【问题讨论】:

    标签: mod-rewrite apache2


    【解决方案1】:

    REQUEST_URI 包含请求的 URI 路径,并且总是以斜杠开头。

    所以模式 ^thumbs/(.*)$ 永远不会匹配,因为它缺少前导 /。但另一个条件 !^/thumbs/(.*)$ 应该匹配每个 URI 路径不以 /thumbs/ 开头的请求。

    【讨论】:

      【解决方案2】:

      我认为这是因为第一个斜线

      RewriteCond %{REQUEST_URI} !^/thumbs/(.*)$
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-08-11
        • 1970-01-01
        • 1970-01-01
        • 2021-06-27
        • 2011-07-02
        • 1970-01-01
        相关资源
        最近更新 更多