这是一个有趣的问题,因为在文档中没有明确解释,我将通过mod_rewrite的源代码来回答; 展示了开源的巨大好处。
在顶部,您将快速发现用于命名这些标志的定义:
#define CONDFLAG_NONE 1<<0
#define CONDFLAG_NOCASE 1<<1
#define CONDFLAG_NOTMATCH 1<<2
#define CONDFLAG_ORNEXT 1<<3
#define CONDFLAG_NOVARY 1<<4
然后搜索CONDFLAG_ORNEXT会基于[OR]标志的存在来确认是否已使用它:
else if ( strcasecmp(key, "ornext") == 0
|| strcasecmp(key, "OR") == 0 ) {
cfg->flags |= CONDFLAG_ORNEXT;
}
该标志的下一个出现是实际的实现,您将在其中找到遍历RewriteRule具有的所有RewriteConditions的循环,并且其基本操作是(剥离,为清楚起见添加了注释):
# loop through all Conditions that precede this Rule
for (i = 0; i < rewriteconds->nelts; ++i) {
rewritecond_entry *c = &conds[i];
# execute the current Condition, see if it matches
rc = apply_rewrite_cond(c, ctx);
# does this Condition have an 'OR' flag?
if (c->flags & CONDFLAG_ORNEXT) {
if (!rc) {
/* One condition is false, but another can be still true. */
continue;
}
else {
/* skip the rest of the chained OR conditions */
while ( i < rewriteconds->nelts
&& c->flags & CONDFLAG_ORNEXT) {
c = &conds[++i];
}
}
}
else if (!rc) {
return 0;
}
}
您应该能够解释这一点;这意味着OR具有更高的优先级,您的示例确实导致if ( (A OR B) AND (C OR D) )
。例如,如果您具有以下条件:
RewriteCond A [or]
RewriteCond B [or]
RewriteCond C
RewriteCond D
它会被解释为if ( (A OR B OR C) and D )
。