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
https://forums.phpfreaks.com/topic/267735-htaccess-conditional-statement/
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]
    

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.