Is this how to use AND, OR for RewriteCond
on Apache?
rewritecond A [or]
rewritecond B
rewritecond C [or]
rewritecond D
RewriteRule ... something
becomes if ( (A or B) and (C or D) ) rewrite_it
.
So it seems like "OR" is higher precedence than "AND"? Is there a way to easily tell, like in the (A or B) and (C or D)
syntax?
This is an interesting question and since it isn't explained very explicitly in the documentation I'll answer this by going through the sourcecode of mod_rewrite; demonstrating a big benefit of open-source.
In the top section you'll quickly spot the defines used to name these flags:
and searching for CONDFLAG_ORNEXT confirms that it is used based on the existence of the [OR] flag:
The next occurrence of the flag is the actual implementation where you'll find the loop that goes through all the RewriteConditions a RewriteRule has, and what it basically does is (stripped, comments added for clarity):
You should be able to interpret this; it means that OR has a higher precedence, and your example indeed leads to
if ( (A OR B) AND (C OR D) )
. If you would, for example, have these Conditions:it would be interpreted as
if ( (A OR B OR C) and D )
.