IT

Apache에서 RewriteCond에 "AND", "OR"을 사용하는 방법은 무엇입니까?

lottoking 2020. 8. 8. 12:06
반응형

Apache에서 RewriteCond에 "AND", "OR"을 사용하는 방법은 무엇입니까?


이것이 RewriteCondApache에서 AND, OR을 사용하는 방법 입니까?

rewritecond A [or]
rewritecond B
rewritecond C [or]
rewritecond D
RewriteRule ... something

됩니다 if ( (A or B) and (C or D) ) rewrite_it.

그래서 "OR"이 "AND"보다 우선 순위가 높은 것 같습니까? (A or B) and (C or D)구문 처럼 쉽게 말할 수있는 방법이 있습니까?


이것은 흥미로운 질문이며 문서에 명시 적으로 설명되어 있지 않기 때문에 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;
}

모든 RewriteConditions를 가진 플래그의 다음 발생은 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 )됩니다.

참고 URL : https://stackoverflow.com/questions/922399/how-to-use-and-or-for-rewritecond-on-apache

반응형