Category : Html | Author : Chtiwi Malek | First posted : 10/20/2012 | Updated : 10/21/2012
Tags : htaccess, redirect, update, apache, iis, http
Redirection to a Maintenance Page with htaccess Redirect

Redirection to a Maintenance Page with htaccess Redirect

When updating or upgrading your website, it is better to inform your user that the site is down for maintenance instead of getting an error or a 404 page.

First you have to create a page called maintenance.htm on your domain root directory containing the message you want to show to your visitor during the upgrade.

Here's the copy/paste code snippet you have to add to .htaccess to redirect all users to a maintenance page no matter which page they requested.
# Redirection to the Maintenance Page
RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^99\.142\.141\.42
RewriteCond %{REQUEST_URI} !/maintenance.htm$
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif)
RewriteRule .* /maintenance.htm [R=307,L]
Line 1 : The first line is just a comment
Line 2 : Activate the Rewrite Engine
Line 3 : Will exclude any request coming from your IP ( in this case) from being redirected, so you can still access your site. Just duplicate this line to exclude other IPs.
Line 4 : Will ensure that any request to the redirection page (maintenance.htm) will not be redirected again, to avoid and infinite loop.
Line 5 : Any request to a jpg, jpeg, png or gif file will not be redirected (so you can show pictures in your redirection file).
Line 6 : This is the actual redirection instruction => any request will be redirected to maintenance.htm with the redirection code 307 (307 Temporary Redirect).

When your website is ready remove these lines, or just mark them as comment in case you need them later.
Comments & Opinions :
Nice! I want you to thank for your time of this wonderful read!!! Your blog posts are more interesting and informative. I very like and visit regularly. -
- by hill climb racing 2 on 9/13/2017
driving direction
I have a similar interest this is my page read everything carefully and let me know what you think.
-[URL=]driving directions[/URL]
- by driving direction on 11/29/2017
- by mmssw on 2/3/2019
Leave a Comment:
Name :
Email : * will not be shown
Title :
Comment :