Security, Wordpress

Create a Maintenance Page in WordPress

Sometimes when you are doing updating or scheduled maintenance for your WordPress blog, i suggest you to make it temporary down while you are updating or maintenance. Temporary down in short time won’t cause any harm to your website, your visitors will understand and could comeback later. As well as crawl bot from search engines, when it see the HTTP Error 503 (Service unavailable), it will comeback again to index your website.

How to create a maintenance page:

  1. Make a design for your maintenance page. SmashingMagazine compiled some good and inspirative maintenance page. Or see mine here.
  2. Create maintenance.php page and put this code in header or top of the script:
    ob_start();
    header('HTTP/1.1 503 Service Temporarily Unavailable');
    header('Status: 503 Service Temporarily Unavailable');
    header('Retry-After: 3600');
    header('X-Powered-By:');
    //Put your design in HTML to the rest
    
  3. Add this to your .htaccess file:
    RewriteEngine On
    RewriteBase /
    RewriteCond %{REMOTE_ADDR} !^125.162.xx.xx #Don't block your own ip
    RewriteCond %{REQUEST_URI} !^/maintenance.php$ [NC] #Prevent forever loop
    RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif) [NC] #Give access to image
    RewriteRule ^(.*)$ http://www.ivankristianto.com/maintenance.php [R=302,L] #temporary redirect
    
  4. Upload everything and done.
  5. If you want to release it comment it in .htaccess:
    RewriteEngine On
    RewriteBase /
    #RewriteCond %{REMOTE_ADDR} !^125.162.xx.xx #Don't block your own ip
    #RewriteCond %{REQUEST_URI} !^/maintenance.php$ [NC] #Prevent forever loop
    #RewriteCond %{REQUEST_URI} !.(jpe?g?|png|gif) [NC] #Give access to image
    #RewriteRule ^(.*)$ http://www.ivankristianto.com/maintenance.php [R=302,L] #temporary redirect
    

The above method is manually make the maintenance page and use .htaccess to do it. That method apply for any website not just for WordPress system. For WordPress you can do it in 2 ways:

  1. Use the .maintenance and maintenance.php file
    • Create a maintenance.php (see the instruction above) and put it under wp-content/ folder
    • Create .maintenance file and fill like this:
      <?php $upgrading = ' . time() + (60 * 60) . '; ?>

      Note: that script means always add 1 hour, so it would be endless.

    • Now you are done.
    • When you finish updating or maintenance just delete or rename .maintenance file so it would back to normal.
  2. WP Maintenance Mode Plugin
    The first 2 method need a little bit programming skill. If you don’t have that kind of skill then you can choose this last method. You can use WP Maintenance Mode plugin, it available free in WordPress plugins repository. WP maintenance mode plugin adds a maintenance-page to your blog that lets visitors know your blog is down for maintenance time. You can visit the plugin page for more details and download link: WP Maintenance Mode.

From all the method i like the manual method using the .htaccess, because it is more general and i can use it in different CMS not just WordPress. And it give me more power to do customization. But you may have different opinion, feel free to use the comment box below to share your thought. Thanks and have a nice day.

Leave a Reply