start | find | index | login or register | edit
2009-07-20
by earl, 3434 days ago
A simple mod_rewrite-based "maintenance mode"

You might have noticed the "down for maintenance" notice earlier today. This was enabled using a simple touch MAINTENANCE in the appropriate directory. Witness the magic of mod_rewrite! You want this as well? Here's the rules used:

RewriteCond %{DOCUMENT_ROOT}/MAINTENANCE -f
RewriteCond %{REQUEST_FILENAME} !maintenance.asis
RewriteRule ^(.*)$ /maintenance.asis [P,L]

With that in place, if a file named MAINTENANCE exists in the document root of your site, all requests will be internally proxied to maintenance.asis. Here's an example for such a maintenance.asis:

Status: 503 Service Unavailable
Content-type: text/plain

the service you're requesting is down for maintenance, it will be back soon.

Obviously, you could also use any other target as well, like a PHP script, for example.

Once that's in place, enabling maintenance mode is a simple as creating said MAINTENANCE file in your document root. To disable maintenance mode, just remove this file again.

As a simple but effective extension, you can allow access on an IP-level during maintenance mode by adding the following rewrite condition:

RewriteCond %{REMOTE_ADDR} !<your-ip-here>

Well, all hail the mighty mod_rewrite! And if you need a stupid "maintenance-only" webserver, have a look at 2006-05-07.
powered by vanilla
echo earlZstrainYat|tr ZY @.
earl.strain.at • esa3 • online for 6493 days • c'est un vanilla site