Reputation: 1640
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 .htaccess
in a RewriteCond
.
I tried:
RewriteCond %{MY_VAR} "123"
and
RewriteCond %{ENV:MY_VAR} "123"
Is this possible ? Thanks for your help.
Upvotes: 1
Views: 100
Reputation: 786031
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$
Upvotes: 1