Forum Moderators: phranque
Do I need to install mod_env in order to use SetEnv?
I'm able to use [E] right now with no problems
But I remember when I uninstalled mod_security and... something else that I don't remember, it had a pretty significant impact on my load time.mod_security may be a special case, because it performs a number of actions on every request; that’s its job. If someone has a spare domain sitting around, I guess they could test-and-compare whether the mere existence of mod_security has an effect, or if it only starts being noticeable once you’ve given it a longish list of patterns to work on.
I'm able to use [E] right now with no problems, but SetEnv would just be easier to read.
Man, I looked EVERYWHERE for that
If all you are doing is passing an env var to your backend script then SetEnv is "better" than mod_rewrite.
However, if you are setting an env var to be processed by other Apache modules then SetEnv is probably processed too late to be useful.
SetEnv is simpler and more permanentDoes “more permanent” mean that some environmental variables disappear if an internal request is looped back through the server, so it hits mod_rewrite more than once? Or only that, since mod_env runs after mod_rewrite, some variables might be changed or re-set?
This technique is offered as an example, not as a recommendation.Dunno about the rest of you, but I find some parts of the Apache docs more helpful than others.
SetEnv is simpler and more permanent
some environmental variables disappear if an internal request is looped back through the server
MYVAR and REDIRECT_MYVAR and REDIRECT_REDIRECT_MYVARMatter of fact, I did notice that when adding environmental variables to the logheaders routine. (Set with SetEnvIf, not Rewrite.) Happily the leading element REDIRECT is in ALL CAPS, so I didn't have to take an extra step to ignore it.
[E=example:Lorem\ ipsum\ dolor\ sit\ amet\%2C\ consectetur] SetEnv example "Lorem ipsum dolor sit amet, consectetur" [E=foo:bar,E=lorem:ipsum] SetEnv foo bar
SetEnv lorem ipsum // assuming the page is index.php
SetEnv foo bar
SetEnvIf REQUEST_URI "index\.php" foo=notbar // assuming the page is index.php
SetEnvIf REQUEST_URI "index\.php" foo=notbar
SetEnvIf REQUEST_URI "!index\.php" foo=bar SetEnvIf REQUEST_URI "index\.php" foo=bar lorem=ipsum SetEnvIfExpr "%{QUERY_STRING} =~ /foo/" foo=bar So it appears that it goes through the entire .conf to run all of the SetEnvIf, then it starts over and runs the SetEnv which would overwrite anything set by SetEnvIf (then it starts over again and runs the RewriteRules).That's your reverse alphabetical order (unless you've expressly told your server to load them in a different order):
# typed up for this, so please forgive any typos
RewriteRule ^ - [E=foo:bar]
RewriteCond %{REQUEST_URI} index\.php
RewriteRule ^ - [E=foo:notbar] by using mod_rewrite for everything, the order of operations appears to be more top-down, which seems to be easier to understand
1. With [E], I had to escape whitespaces, and commas didn't work at all, so I had to do an alternative; eg,
[E=example:Lorem\ ipsum\ dolor\ sit\ amet\%2C\ consectetur]
"[E=example:Lorem ipsum dolor sit amet consectetur]"
RewriteCond "Lorem ipsum dolor sit amet, consectetur" (.*)
RewriteRule ^ - [E=example:%1]
...run all of the SetEnvIf, then it starts over and runs the SetEnv which would overwrite anything set by SetEnvIf (then it starts over again and runs the RewriteRules).
That's your reverse alphabetical order (unless you've expressly told your server to load them in a different order):
mod_setenvif
mod_setenv
mod_rewrite
So I guess "ap_expr" means PCRE?
1. Using PHP's print_r($_SERVER), I see a variable of [HOME] that's set to /home/example. But when I do this:
SetEnv foo ${HOME}
I see that foo is set to /root. Why? I don't remember where I found the ${whatever} format, but it's the only thing I could find that worked at all. Am I strictly limited to accessing Remote_host, Remote_addr, Request_method, Request_protocol, and Request_URI?
2. What's the purpose of PassEnv? The docs explanation makes no sense.
This isn't quite right...Whoops! I should have double-checked the module name before posting. (I don't use SetEnv and related directives--though I see they are permitted in htaccess--so the module name isn't internalized like mod_rewrite and similar names*.)