Simple Down for Maintenance Page using .htaccess

.htaccess

To put a site into maintenance mode put either of the following in an .htaccess file in the site root.

1) Very simple

#close the site down ############################################
RewriteEngine On
ErrorDocument 403 /maintenance.php
order deny,allow
deny from all
allow from xxx.xxx.xx.xxx
#end of closed site rules##################################

The “allow from” line permits access only from the given IP address.

2) More complex but more flexible and might work better on some servers

# MAINTENANCE-PAGE REDIRECT
<IfModule mod_rewrite.c>
 RewriteEngine on
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REMOTE_ADDR} !^123\.456\.789\.000
 RewriteCond %{REQUEST_URI} !/maintenance.php$ [NC]
 RewriteCond %{REQUEST_URI} !\.(jpe?g?|png|gif) [NC]
 RewriteRule .* /maintenance.php [R=302,L]
</IfModule>

Allowed IP addresses can be listed as shown. Images aren’t blocked and maintenance.php is allowed to prevent looping.

maintenance.php

Create the page “maintenance.php”  which can detail the reason why the site is down and give contact details to, hopefully avoid a missed sale or booking.

Example Maintenence.php:

<?php
//maintenance page as 403
?>
<div style="text-align:center;width:640px;margin:100px auto 0">
<p>This site is getting reloaded</p>
<p>We are updating our website so we will be offline for a short while.</p>
<p>Apologies for the inconvenience, we should be back online in an hour or so.</p>
<p>In the meantime if you want to contact us you can phone or email us:</p>
<ul>
<li>Phone +64 3 111 1111</li>
<li>Email <a title="Send us an email" href="mailto:info@domain.co.nz">info@domain.co.nz</a></li>
</ul>
</div>
<?php
//eof
?>