Jump to content

htaccess conditional statement


onlyican

Recommended Posts

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.

Link to comment
Share on other sites

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]
    

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.