WordPress Code Snippets

A fresh mix of code snippets and tutorials

Maintenance mode via .htaccess

117

For WordPress users there are at least three great plugins that make maintenance mode just dead-simple. Even so, here is how to do it with .htaccess.

To enable maintenance mode for your site, place this code at the top of your site’s root .htaccess file:

Some notes about this snippet:

  • Edit the IPs in the first container with your own values
  • The W3C Validator is not allowed unless you uncomment its line
  • Change example.com with your own domain name
  • Edit the Header directive with any amount of time

Then, with that code in place, your server is going to respond with the file, maintenance.html, if it exists. You can either delete the ErrorDocument directive or create a maintenance.html file. Here is an example for a very basic maintenance page:

Once that’s included in your maintenance file, put the file in the root directory of your site. Then visit your site via proxy server to verify that everything is working.

This is the technique I use for my own sites. For some projects I create an elaborate maintenance page with interactive functionality, but for quick site updates the simple HTML file works great.

Note that you can skip serving an actual maintenance file and just send the default server response instead. To do so, delete or comment out the ErrorDocument directive in the .htaccess code above.

You may also want to check out this related post for some more ideas: Allow access to external IPs during development

WordPress Plugins

And just because I care, here are the top three “maintenance mode” plugins for WordPress:

1 Minute Quickie

Update (2013/08/22): Here is a much simpler “on-the-fly” snippet that I use when doing just the quickest updates on sites:

Peace out.

Further reading

Learn more

.htaccess made easy