Apache SetEnvIf trouble
Asked Answered
E

1

4

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?

Ethiopic answered 2/9, 2009 at 17:16 Comment(0)
C
7

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.

Cubit answered 2/9, 2009 at 17:28 Comment(2)
So is there a way to test for a variable set with SetEnvIf?Ethiopic
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.Cubit

© 2022 - 2024 — McMap. All rights reserved.