Htaccess service mode allows certain directories

Therefore, I use the following to force my site into maintenance mode when updating some things:

# MAINTENANCE-PAGE REDIRECT <IfModule mod_rewrite.c> RewriteEngine on RewriteCond %{REMOTE_ADDR} !^23\.1\.12\.167 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC] RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC] RewriteRule .* /maintenance.html [R=302,L] </IfModule> 

This worked fine, but now I have a situation where in maintenance mode I want to exclude the transfer of a specific directory to the maintenance.html file and, rather, show their normal contents.

So it would be something like:

 root/ .htaccess maintenance.html index.html everything.else.html /do_not_display_me /display_me_always 

Not sure if this is possible from the root .htaccess level, or if I need to handle sub-dir.htaccess files, any help would be appreciated.

+1
source share
1 answer

That should do the job. It tells Apache not to overwrite these folders (which eliminates maintenance rules, since the rewrite chain will never reach them).

 # activate rewrite engine RewriteEngine on # always allow these folders RewriteCond %{REQUEST_URI} ^/display_me_always [OR] RewriteCond %{REQUEST_URI} ^/another_folder [OR] RewriteCond %{REQUEST_URI} ^/even_more_folders RewriteRule .+ - [L] # maintenance rules RewriteCond %{REMOTE_ADDR} !^23\.1\.12\.167 RewriteCond %{REQUEST_URI} !/maintenance.html$ [NC] RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC] RewriteRule .* /maintenance.html [R=302,L] 
  • The case of the letter matters, so if you need to match the insert with the text of the mixed input NC, in [OR] .
  • You can add a slash / at the end of the folder names if you have files in the root folder with the same name.
+2
source

All Articles