问题
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?
回答1:
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.
来源:https://stackoverflow.com/questions/1369023/apache-setenvif-trouble