.htaccess Maintenance Redirect

In my line of work, I deal with a lot of people performing maintenance on their website. I often get asked how to put a redirect in place to a maintenance page or area. I get asked so much, in fact, I decided to post this on my blog.

By using the following code within a .htaccess file, you will be able to direct visitors to a maintenance page no matter which part of your site they request. You will want to use your own file name, of course, if maintenance.php does not suit you. Once your maintenance has completed, you can simply delete the code from the .htaccess file or comment it out (by adding ‘#’ to each line, at the beginning).

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.php$
RewriteRule ^(.*)$ http://yourdomain.com/maintenance.php [R=503,L]

If you need to redirect all visitors to the maintenance page, but you still want to have access (or possibly, a developer), you can modify the above code to the following. You will need to change the IP address to that of your own or whoever you wish to give access to.

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^255\.255\.255\.255
RewriteCond %{REQUEST_URI} !^/maintenance\.php$
RewriteRule ^(.*)$ http://yourdomain.com/maintenance.php [R=503,L]

It is as simple as that. Have fun!

Eric Sizemore

About The Author

I’m a 28 year old Web Developer, Programmer, and Domainer. I specialize in PHP and MySQL, and have used both extensively since early 2005.

No Comments

Leave A Reply