We've touched on this in other threads, but I wanted to clarify without taking them off topic.
It's my understanding that mod_rewrite (eg, RewriteRule) runs in the order it's presented. mod_setenv (eg, SetEnvIf) runs before everything else, and mod_env (eg, SetEnv) runs after everything else. So if I have this:
SetEnv this that
ReWriteRule ^ - [E=foo:bar]
SetEnvIf ^ ^ lorem=ipsum
then lorem is set first, foo is set second, and this is set last. Right?
Assuming so:
1. I recognize that SetEnv is subjectively easier to read than RewriteRule, but is there any other advantage to it? I guess if you have a reason to write it higher in the script but intentionally want it to run last, but I can't think of any example of this where it couldn't just be written at the end.
2. SetEnvIf is shorter than a series of RewriteCond => RewriteRule, but it seems like using it just once means that I need to use it exclusively in order to prevent confusion. Is there a DISadvantage to using
SetEnvIf ^ ^ foo=bar (which should match in all cases, making it seem identical to SetEnv or RewriteRule other than the order of operation)?
I'm sure that Apache had some reason for creating the modules to run in this order, but I honestly don't understand it. It feels highly inefficient if Apache has to scan the entire config for any SetEnvIf, then scan again for any RewriteRule, then scan a third time for any SetEnv.