SiteCrafting, Inc.

10 Nov

Hiding Behind a Maintenance Wall

A common task in web development is updating a live server. There are many ways to do it, but some of them require downtime. Rather then turn users away, it is best practice to put up a maintenance page. But what if you still need access to the site while you are updating it? .htaccess and Cookies to the rescue!


Most people use .htaccess for simple mod-rewrites (is there such a thing?). Usually, this follows some regex pattern that forwards off to a PHP page to give the user some pretty URLs. You can use this same .htaccess to create a wall between your users and the site, allowing you to put up a maintenance page while still giving you access. To do this, add the following lines of code to the top of your .htaccess file:
RewriteCond %{HTTP_COOKIE} !^.*maintenance.*$ [NC]
RewriteRule ^.*$ maintenance.html [QSA,L]
What this does is check your cookies for one called maintenance. If you have this cookie, it will continue with your session like normal. If you are missing the cookie, you are simply forwarded to a friendly maintenance message.

There are several ways to get the cookie setup. Personally, I just use a bookmarklet to inject the cookie into my browser. If your clients need access, then add a get variable to the url and have the maintenance page add the cookie.

Enter Maintenance

Coding Techniques, Odds 'n Ends, Web Hosting
by Paul Sayre | 11/10/2009 11:02am | Comments (0)

No comments found.


Leave a Comment




* required    Comment Guidelines