Using .htaccess to show a maintenence page
Written on March 24, 2009 – 8:25 am | by David Windell
Close your website temporarily
This week I are be mostly working on a live website. Ha, ok enough fast show malarky! Working on a clients site we needed to roll out quite a large patch to their existing website. As the site they use is E-Commerce based we had concerns that a user might try to make a purchase during the upgrade process so we decided to have the site redirect to a maintenance page using the .htaccess file.
That’s all very well, but what about us, we needed to see the changes we were making working live. This nifty little script below does just that, if you replace the 111.111.111.1 with the external IP of your machine it will bypass the rules below that line thus giving you access to the site whilst others are redirect to maintenance.html. Simples.
The .htaccess file
RewriteBase / RewriteCond %{REMOTE_ADDR} !^111\.111\.111\.111 RewriteCond %{REQUEST_URI} !^/maintenance\.html$ RewriteRule ^(.*)$ http://www.example.co.uk/maintenance.html [R=307,L]