Use RewriteCond based on environment variable in .htaccess
.htaccess, apache, mod-rewrite
Solution
mod_rewrite doesn't use variables set via SetEnv, instead use this method:
#set to 'live' or 'maintenance'
RewriteRule .* - [E=STATUS:maintenance]
#If the ENVIRONMENT variable is 'maintenance' then show a maintenance page
RewriteCond %{REQUEST_URI} !maintenance.html [NC]
RewriteCond %{ENV:STATUS} ^maintenance$
RewriteRule ^.*$ /maintenance.html [L]
The first line of the bottom three, makes sure that once the user is redirected to the file "maintenance.html", it will not be redirected again. Else the user keeps getting redirected to the same file, causing an 500 internal server error saying "AH00124: Request exceeded the limit of 10 internal redirects due to probable configuration error."
Problem
I am trying to define an environment variable in my .htaccess file, and then run a rewrite condition using that variable. Below is what I have in my .htaccess file, but the rewrite is not working: ``` RewriteEngine on #set to 'live' or 'maintenance' SetEnv ENVIRONMENT maintenance #If the ENVIRONMENT variable is 'mainetnance' then show a maintenance page to the users RewriteCond %{ENV:ENVIRONMENT} maintenance RewriteRule ^(.*)$ /maintenance.html ``` The purpose of this is to set the site to maintenance mode programmatically by having PHP edit the .htaccess file when it receives a post request from one of GitHub's hooks to pull the repo for an update.