adrien54 adrien54 - 1 year ago 74
Apache Configuration Question

Access in .htaccess an environnment variable defined in VirtualHost

I have defined in the apache configuration file an environnment variable in the vhost:

<VirtualHost *:443>
SetEnv MY_VAR 123

I can access it in my application in PHP:

echo $_SERVER['MY_VAR'] //display 123

However I can't find a solution to access it in my
in a

I tried:

RewriteCond %{MY_VAR} "123"


RewriteCond %{ENV:MY_VAR} "123"

Is this possible ? Thanks for your help.

Answer Source

You can use SetEnvIf module for this instead of SetEnv:

SetEnvIf Host ^ MY_VAR=123

This will set MY_VAR as 123 for any web request.

Then you can use this RewriteCond in your .htaccess:

RewriteCond %{ENV:MY_VAR} =123

Or using regex:

RewriteCond %{ENV:MY_VAR} ^123$
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download