Quantcast
Viewing all articles
Browse latest Browse all 10

Using .htaccess to suspend an entire site while still working on it

Sometimes, when you’re working on a web site, you need to make some changes that could cause problems if there is someone else using the site at the time. The obvious solution is to suspend the site — e.g. put up a ‘this site is down for maintenance’ page — but how do you do this while still being able to view and work on the site yourself?

In fact, it’s really quite easy, using .htaccess. Simply put, you use mod_rewrite to redirect all requests to the maintenance page, unless the user’s browser has a particular cookie.

RewriteEngine On
RewriteBase
RewriteCond %{HTTP_COOKIE} !^.*secret-cookie.*$ [NC]
RewriteRule .* maintenance-page.html [NC,L,R=503]

Clearly you can change the name of the cookie from ‘secret-cookie’ to whatever you like. Its value isn’t important. And of course, you can change the name of your maintenance page.

Update: as suggested by Michael, below, I’ve added the R=503 status code to indicate that the service is temporarily unavailable.

Now you just need to create the cookie in your browser. Personally I use the FireCookie extension for Firebug which makes this very easy.

That’s it!

Image may be NSFW.
Clik here to view.

Viewing all articles
Browse latest Browse all 10

Trending Articles