Redirect to maintenance page during upgrade using .htaccess

Redirect your visitor to maintenance page is a must when you are upgrading your site. Now you can redirect your user to maintenance page easily by using .htaccess file. I guess you do not want your visitor to see an error page or 404 page during your server upgrade. So just follow the steps below to create a .htaccess file to redirect your visitor to maintenance page during upgrade:-

  • Create a file and name it .htaccess with the content below:-

    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/maintenance.html$

    RewriteRule $ /maintenance.html [R=302,L]

  • Once the file is created, put it at your root directory. (This will be in http://www.yourdomain.com/.htaccess)
  • Create another file name it maintenance.html (just put wat messeage you want to show to your visitor during the upgrade) and put it at the root directory too. (This will be in http://www.yourdomain.com/maintenance.html)
  • Now you can try to browse your site and it should now redirect you to maintenance.html
  • Since you are going to perform the upgrade, you have to able to browse the site. So you have to exclude your IP in the .htaccess file. Now you have to add a line in the .htaccess file as below:-

    RewriteCond %{REMOTE_HOST} !^888\.888\.888\.888

    ** Please change the fake ip (888.888.888.888) to your own IP

  • Now your .htaccess file should look like below.

    Options +FollowSymlinks
    RewriteEngine on
    RewriteCond %{REQUEST_URI} !/maintenance.html$
    RewriteCond %{REMOTE_HOST} !^888\.888\.888\.888

    RewriteRule $ /maintenance.html [R=302,L]

Your visitor should be redirected to maintenance page by the .htaccess we set just now and you should be able to browse your site and perform your upgrade.


Note: .htaccess only works in apache webserver, if you do not know what web server you are on, your can consult with your server administrator for more details. This .htaccess using apache mod_rewrite module. Please ensure you have mod_rewrite installed and enabled.

Technorati Tags: , , , , , , , ,

Are you on the computer constantly? If you love technology, sign online today for the best in cheap computer software!  The internet affects us everyday.  If you use the internet for personal or business use, you want the best computer software.  Whether you need cheap video editing software or photo editing software, the internet is your best source to shop!

Share and Enjoy:
  • Reddit
  • BlinkList
  • del.icio.us
  • Digg
  • Fark
  • IndianPad
  • StumbleUpon
  • YahooMyWeb
Posted at January 12th, 2007 by chua

If you think this article helps you to solve your problem and clear your headache, feel free to buy me a drink :)

Related Post

5 Responses to “Redirect to maintenance page during upgrade using .htaccess”

  1. Blogger Anxiety - Hosting and Themes » Reader Appreciaton Project Says:

    [...] while you are upgrading or tweaking your blog. One technique I have personally used is to manually set up a maintenance page and modify the htaccess [...]

  2. RD Says:

    Thanks for your straightforward tip. My Google search turned up many pages with much more complicated methods (a silly DNS hack, restarting the whole Apache server with a different config., etc.).

    Your method is definitely the easiest and most flexible. Thank you!

  3. TC Says:

    An alternative to the solutions I’ve found (believe it or not, I don’t have access to using mod_rewrite), is to create a directory htdocs_maintenance which holds my html maintenance page under the guise of both the index page and the 404 page, and then update the DocumentRoot in the main conf file. Works great!

  4. JD Says:

    This is pretty smooth. The only issue I have with it is that 302 is maybe not really the right response code for this situation; 503 would be more correct, but RewriteRules won’t let you use a 500-series code! The only way I’ve found around it is to redirect to a CGI script, where you can set your own return code, but I’d rather not have to use a script.

    I used to use something like TC mentions - that’s nice and easy too, although it does return either 404 or 200, which are not really 100% correct either. Getting Apache to actually return a 503 for all requests turns out to be surprisingly nontrivial. The visible effect of all these different ways is likely to be the same, but I’m just looking for the “philosophically correct” way.

  5. Aless{a}ndro Says:

    Hello, thanks for the advice.
    You can get the same result without mod_rewrite ?

    My provider has not installed the mod_rewrite module. :(

Leave a Reply