onlyican Posted August 29, 2012 Share Posted August 29, 2012 Hi I am trying to build a conditional statement into a htaccess file for maintenance mode. Basically, I have a set of rules to check if the URI is not the maintenance file, or the img dir or css dir or a group of IPs, then put show maintenance file But Instead of having to comment out the block (as in htaccess its hashing out per line) I wanted a var and conditional within the htaccess file Something like MAINTENANCE_MODE = false if (MAINTENANCE_MODE) { RewriteCond %{REMOTE_HOST} !^192.168.1.1 RewriteRule $ /maintenance.html [L] } else { RewriteRule maintenance.html index.php [R=302] } Cheers in advance. Quote Link to comment https://forums.phpfreaks.com/topic/267735-htaccess-conditional-statement/ Share on other sites More sharing options...
onlyican Posted August 29, 2012 Author Share Posted August 29, 2012 Done it Code example # Change :false to true to put in maintenance mode RewriteRule .* - [E=MAINTENANCE:false] RewriteEngine on # Redirect to maintenance file if in maintenance mode. RewriteCond %{ENV:MAINTENANCE} ^true$ RewriteCond %{REQUEST_URI} !/maintenance.html$ RewriteCond %{REQUEST_URI} !/css/ RewriteCond %{REQUEST_URI} !/img/ RewriteRule $ /maintenance.html [L,R=302] # Redirect away from Maintenance file is not in maintenance mode. RewriteCond %{ENV:MAINTENANCE} !^true$ RewriteRule ^maintenance.html /index.php [L,R=301] Quote Link to comment https://forums.phpfreaks.com/topic/267735-htaccess-conditional-statement/#findComment-1373506 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.