I set an environment variable in httpd-vhosts.conf
SetEnv EARLY_VAR 1
I try setting special rules based on its value in .htaccess
<If "%{ENV:EARLY_VAR} == '1'">
SetEnv TEST_VAR if_branch
</If>
<Else>
SetEnv TEST_VAR else_branch
</Else>
I expect TEST_VAR
environment var to equal if_branch
. In PHP
var_dump(getenv('EARLY_VAR')); // string '1'
var_dump(getenv('TEST_VAR')); // string 'else_branch'
I also tried setting EARLY_VAR
in .htaccess
above the If/Else, both using SetEnv
and SetEnvIf
. Always the Else branch is executed.
Why is this?
Apache 2.4
%{ENV:
as a valid expression here ~ httpd.apache.org/docs/2.4/expr.html. There is theenv
function though – Mcknight%{ENV:
is also valid.and would be expanded as"%{" funcname ":" funcargs "}"
– Margoriemargotvariable
. The list of functions is also provided a little down the page. – Margoriemargot