April 15, 2011 by  

WordPress Series: Create a Maintenance Page

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
How to use:
1. Create a maintenance.php (see the instruction above) and put it under wp-content/ folder
2. Create .maintenance file and fill like this:

<?php
function is_user_logged_in() {
    $loggedin = false;
    foreach ( (array) $_COOKIE as $cookie => $value ) {
        if ( stristr($cookie, 'wordpress_logged_in_') )
            $loggedin = true;
    }
    return $loggedin;
}
if ( ! stristr($_SERVER['REQUEST_URI'], '/wp-admin') && ! stristr($_SERVER['REQUEST_URI'], '/wp-login.php') && ! is_user_logged_in() ){
    $time = strtotime("+1 hour");
	$upgrading = $time;
}
?>

Note: that script means always add 1 hour, so it would be endless.
3. Now you are done.
4. 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.
Sample screenshots:

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.

Related Reading:
This Post is a WordPress Series Article
WordPress Blog Optimization
WordPress Configuration Checklist

What people search:

Post comment as twitter logo facebook logo
Sort: Newest | Oldest

This is really an informative post..Thanks for giving the instruction of how to create a maintenance page....It will be really helpful to us..