2011/05/12

mod_rewrite and site maintenance

By nikky

If you’re work­ing on updat­ing or rewrit­ing a pro­duc­tion site, it may be use­ful to have a mod_rewrite rule that will auto­mat­i­cally send all traffic–except IPs you specify–to a main­te­nance page. This will let you com­mu­ni­cate to your users while still allow­ing you and your staff to work on the site unhin­dered. In this case, 25.254.253.252 and 1.2.3.4 will be allowed to visit the site as nor­mal, and every­one else would be redirected.

RewriteEngine On
RewriteCond %{REMOTE_ADDR} !255.254.253.252 [NC]
RewriteCond %{REMOTE_ADDR} !1.2.3.4 [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule !maintenance.html$ maintenance.html [R=307,L]

Comments are closed.