Put Your Website in Maintenance Mode With .htaccess

Sooner or later you’ll probably run into a case where you need to put up a “maintenance mode” page while working on the site (e.g. while moving a site to a different server). What’s the best way of doing that? First you create a small, static HTML page that will appear to your visitors, then you put this at the top of your .htaccess file:

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/berightback\.html$
RewriteRule ^(.*)$ http://example.org/berightback.html [R=307,L]

If you still need to be able to access the live site while you perform the maintenance, you can add a condition permitting requests from your IP address. This line should be placed after the RewriteBase / line:

RewriteCond %{REMOTE_ADDR} !^00\.000\.000\.000

Be sure to replace the zeros in 00\.000\.000\.000 with the digits from your own IP address, which you can find by visiting WhatIsMyIP.com.

  • http://visionwidget.com Joseph

    The simplest way would be to centralize some of the logic regarding site generation. This way you could turn maintenance mode on and redirect any non admins to a different page. This would not be hard to do, as I imagine you have some code that keeps popping up all over the place, so just extend the login functionality to check for a global variable (if you don't have any common global variables across your page you could just set it in .htaccess via setenv).

    • http://intensedebate.com/people/redwall_hp redwall_hp

      Yes, that probably is the optimal path to take in applicable cases. (The "Maintenance Mode" plugin is a great way to handle this in WordPress.) There's always someone who would prefer the .htaccess though.

  • http://planetozh.com/ Ozh

    [polldaddy 2039090 http://answers.polldaddy.com/poll/2039090/ polldaddy]

  • http://planetozh.com/ Ozh

    (ok I admit I just wanted to test this "add poll within comment" stuff :)

    • http://intensedebate.com/people/redwall_hp redwall_hp

      Hehe. Fine with me as long as "Totally" stays the most-voted option. ;)

  • http://yaegerdesign.net/ Yaeger Design

    Perfect! I love the fact that we can exclude our local IP. Just what I needed for this new project…

  • http://www.soulsanctuarymusic.com Afterlife

    Thank you, this is a great help in setting up a new site of mine. If I’m forwarding to the front page of a different domain than the .htaccess is hosted on, do I just change RewriteCond %{REQUEST_URI} !^/berightback\.html$ to index.php?