Enable Maintenance Mode With .htaccess

Sometimes when you are upgrading your blog or your website, it’s wise and highly recommended that your block all your visitor and redirect it to maintenance page. So your visitors know and come back later. You can redirect your visitors to maintenance page with redirect 307 (temporary redirect). This redirect 307 won’t harm your server and SEO in search engine. When Google bot saw this redirect code, it will come back later and index your page again.

To redirect all your visitors except you to maintenance page, you can use .htaccess. See the code below:

RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^123.456.78.90 #your ip address
RewriteCond %{REQUEST_URI} !^/maintenance.php$ #maintenance page
RewriteRule ^(.*)$ http://www.ivankristianto.com/maintenance.php [R=307,L] #path to maintenance page

Code explanation: it will check the visitors ip, if it is match with the ip whitelist then do not redirect to maintenance page. If doesn’t match, it will check if it is request to maintenance page, if yes then do not redirect otherwise it will go to endless loop. If not redirect to maintenance page.

And in your maintenance.php you should add this code:

header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');

Code explanation: it will says to the browser that your service is temporary unavailable with 503 status code. And also tell any search engine bot to comeback again in 3600 seconds or 1 hour.

That’s it, don’t forget to turn it off when you are done maintenance or upgrade your websites/blogs. To turn off just comment the last 3 lines with “#” at the beginning of the line.


  1. MaxKiseljov says:

    Nice Ivan! I think I’ll be using this in a month or two…

Give me your feedback

This site uses Akismet to reduce spam. Learn how your comment data is processed.