Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I've got a RewriteCond in a .htaccess similar to:

RewriteCond "%{ENV:FOO}" =bar

But the ${ENV:FOO} is being expanded to the value of FOO, it's always blank.

For example, if I SetEnv FOO "bar" just before the RewriteCond, then crank up the RewriteLogLevel, I get this in my rewrite log:

RewriteCond: input='' pattern='=bar' => not-matched

What am I doing wrong here? How can I make environment variables expand inside of RewriteConds?

Also, if I add a silly RewriteRule like RewriteRule .* %{ENV:FOO}, I can see in the rewrite log that the variable is being correctly expanded there.

My Apache version is 2.2.17.

Edit: I've found another reference to this problem. It seems like a “solution” is to use SetEnvIf instead of SetEnv… =\

Additionally, it doesn't seem like the location of the SetEnv has any effect. I've put it both in httpd.conf and in the .htaccess, and neither work.

share|improve this question
add comment

1 Answer

up vote 1 down vote accepted

Ah, here we go. From the SetEnv documentation (under "caveats"):

The SetEnv directive runs late during request processing meaning that directives such as SetEnvIf and RewriteCond will not see the variables set with it.

So, for now, I guess I'm using:

SetEnvIf _ .* FOO=bar
share|improve this answer
    
Woot! I've been fighting with this for days. Thanks! –  baudtack Aug 23 '11 at 17:07
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.