【问题标题】:Check URL and stop processing using htaccess检查 URL 并使用 htaccess 停止处理
【发布时间】:2012-11-07 04:02:33
【问题描述】:

我想使用 htaccess 检查 URL。开发人员可能想要运行特殊文件 - specialfile.php。我使用 htaccess:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} /specialfile\.php$
RewriteRule .* [L]   #don't change adress
RewriteRule ^$ public/index.html [NC,L]
RewriteRule (.*) public/$1 [NC,L]

我的想法是:如果 rewriteCond %{REQUEST_URI} !/specialfile.php$ true 比 htaccess 应该使用 RewriteRule .* [L] - 这应该意味着 specialfile.php 将被运行,这一切。但它不起作用,因为它运行下一条规则:RewriteRule (.*) public/$1 [NC,L]。

【问题讨论】:

    标签: apache mod-rewrite


    【解决方案1】:

    我认为您没有正确使用RewriteCond。这些条件只会影响下一个RewriteRule

    查看the example on the Apache Homepage。由于您的第二个 RewriteRule 已评估,我认为您的条件不正确。要获得有关重写的更多信息,您应该提高日志级别。这个is also documented here

    您的第二条规则^$ 只匹配一个空请求顺便说一句。这就是为什么它可能无法按预期工作的原因。

    【讨论】:

      猜你喜欢
      • 2016-03-07
      • 2020-10-26
      • 1970-01-01
      • 1970-01-01
      • 2012-05-13
      • 1970-01-01
      • 2018-07-13
      • 1970-01-01
      • 2013-04-09
      相关资源
      最近更新 更多