【问题标题】:RewriteCond expr "true" => not matchedRewriteCond expr "true" => 不匹配
【发布时间】:2012-07-24 11:12:53
【问题描述】:

这是我的 mod_rewrite 配置:

RewriteEngine On
RewriteCond expr "true"
RewriteRule .? - [L]

RewriteRule ^(.*)$ $1 [QSA,L]

这里是相关的日志输出:

RewriteCond: input='expr' pattern='true' => not-matched

Apache 文档说

语法:RewriteCond TestString CondPattern

如果 TestString 具有特殊值 expr,则 CondPattern 将为 被视为ap_expr

在下面的示例中,-strmatch 用于将REFERER 与 站点主机名,以阻止不需要的盗链。

RewriteCond expr "! %{HTTP_REFERER} -strmatch '*://%{HTTP_HOST}/*'" RewriteRule ^/images - [F]

因此,如果 CondPattern 将被视为 ap_expr 并且 ap_expr 可以根据定义明确为 true 那么为什么最简单的可能表达式适合该模式不起作用?确切地说,no 匹配表达式对我有用。有没有人可以验证这种技术是否适用于任何人?

因为我实际上有一个非常复杂的表达式,用传统的 mod_rewrite 条件无法完成,所以知道我是否可以使用这种方法对我来说非常重要。

编辑:

对于懒惰的人,这里直接从here复制了ap_expr的BNF定义:

expr        ::= "true" | "false"
              | "!" expr
              | expr "&&" expr
              | expr "||" expr
              | "(" expr ")"
              | comp

【问题讨论】:

  • 你确定你使用的是 apache 2.4 吗?
  • @JonLin 天哪!你是对的,我尝试了apache -v,它给了我2.2.16:O 和the documentation of 2.2 真的不包含这个功能。谢谢,请发表您的评论作为答案,以便我接受。 (我永远不会明白,为什么 确定性 答案经常像 cmets 一样发布,因为即使这不是 my 解决方案,它也会是另一个解决方案!所以它是100%答案。)

标签: apache mod-rewrite


【解决方案1】:

您确定您使用的是 apache 2.4 吗? ap_expr 是所有新功能,属于 2.4 功能集的一部分,而不是 2.2 的一部分。

【讨论】:

    猜你喜欢
    • 2020-04-05
    • 1970-01-01
    • 1970-01-01
    • 2016-10-16
    • 1970-01-01
    • 1970-01-01
    • 2012-09-07
    • 2017-11-23
    • 1970-01-01
    相关资源
    最近更新 更多