这是一个有趣的问题,由于文档中没有非常明确地解释它,我将通过 sourcecode of mod_rewrite 来回答这个问题; 展示了开源的一大优势。
在顶部,您会很快发现defines used to name these flags:
#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 确认使用based on the existence of the [OR] flag:
else if ( strcasecmp(key, "ornext") == 0
|| strcasecmp(key, "OR") == 0 ) {
cfg->flags |= CONDFLAG_ORNEXT;
}
标志的下一个出现是actual implementation,您将在其中找到遍历 RewriteRule 所具有的所有 RewriteConditions 的循环,它的基本作用是(为了清晰起见,已剥离,添加了 cmets):
# 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 )。