views:

466

answers:

1

I have the following in my .htaccess file:

SetEnvIf Host "^example\.com$" myvar=1
<IfDefine myvar>
  RewriteRule ^(.*)$ index2.php?q=$1 [L,QSA]
</IfDefine>

As far as I can tell, this should be working properly. However, "myvar" does not appear to get defined when I visit from example.com. I know that I have the mod_setenvif.c enabled (I've verified with an <IfModule> block).

Any ideas why "myvar" isn't getting defined?

+3  A: 

This is really a ServerFault question, but anyway: IfDefine doesn't test environment variables, it tests the configuration options that were passed to Apache at startup. So for example, if you ran

apache2 -D MYVAR

then a section

<IfDefine MYVAR>
    ...
</IfDefine>

would get executed.

I'm not sure if there's any Apache configuration directive that acts as a conditional for environment variables, like you're looking for.

David Zaslavsky
So is there a way to test for a variable set with `SetEnvIf`?
Dave DeLong
You can use `RewriteCond` to create a rewrite condition that depends on the value of an environment variable... other than that, I'm not sure if there are other directives that use environment variables. They're mostly for CGI scripts etc.
David Zaslavsky