I'm struggling to figure out how to get environment variables to work using SetEnvIf based off my scenario, and was wondering if somebody can tell me how to do it, or give an example.
My outcome is that I need the following redirect to fire based off the environment vars, I've got other cases that will also need to use this logic.
I've got the below, so the redirect only happens on production
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{ENV:environment} production
RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
</IfModule>
I was hoping that I could setup the following, however cannot figure it out.
SetEnvIf environment ^(.*)$ environment=production #set it to production, if it is not already set?
SetEnvIf Host ^staging. environment=staging
SetEnvIf Host .dev$ environment=wamp
Ideally my psudo code would be
SetEnvIf environment is not set, set to production
SetEnvElse host starts with staging, set to staging
SetEnvElse host ends with dev, set to wamp
Then in my PHP I've got
<?php
if( getenv('environment') ){
exit(getenv('environment'));
}
else {
exit("environment not found");
}
And my output is definitely
environment not found
I'm accessing owen.jekyll-test.dev
Can anybody point me in the direction as to what I'm doing wrong?