Create a decent “sorry this site is down for maintenance” page with a “Have a Nice Day” message, then when you do need to upgrade things use the following htaccess rewrite rule to forward all traffic to this page.

Two solutions below. Both need you to have an HTML maintenance page ready. Both block every IP address other than yours – you need to be able to check everything’s working before you allow folks back, right? [Replace 0.0.0.0 with your own!]

Maintenance option 1 – redirect everything to a particular directory

[Redirects all traffic to example.com/maintenance/index.html]

RewriteEngine on
RewriteCond %{REMOTE_ADDR} !^0.0.0.0$
RewriteRule !maintenance/index.html /maintenance/index.html [L,NC,R=302]

Maintenance option 2 – redirects everything to a subdomain

[Redirects all traffic to a subdomain. From Ask Apache (I like)]

ErrorDocument 403 http://www.sub-domain.example.com/
Order deny,allow
Deny from all
Allow from 0.0.0.0

 

Last updated on 9th March 2020