Don wanted a way to block access to his blog while he was fiddling with it. He found information about the 503 code online.
Of course, they want to return different codes for search engines and for users. We figured we wanted to return the same thing for users and search engines; after all "Service Unavailable" is the actual status, regardless of who's visiting. The only exception should be the blog maintainer.
Here's the .htaccess we worked out:
CODE:
RewriteEngine On
RewriteBase /serendipity
# Allow blog maintainer back in
RewriteCond %{REMOTE_HOST} !^your\.IP\.address\.here
# Don't loop forever
RewriteCond %{REQUEST_URI} !^/503\.php
RewriteRule .* 503.php [L]
And here's the 503.php file I like:
CODE:
<?php
header('HTTP/1.1 503 Service Temporarily Unavailable');
header('Status: 503 Service Temporarily Unavailable');
header('Retry-After: 3600');
header('X-Powered-By:');
?><!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>Get Off My E-Lawn!</title>
</head><body>
<h1>Get Off My E-Lawn!</h1>
<p>
I'm busy maintaining the site. Please don't step on the grass.
</p><p>
I should be ready for visitors again in under an hour.
</p>
</body></html>
We use a PHP file so that we can set the header, and so we can include a retry period for search engines.
If you're one of the few whose server allows [R=503] in the .htaccess, there's an even easier way outlined in the article details.
I didn't really want to have a separate document for my maintenance, and I especially didn't want to run PHP just to output the appropriate header. Unfortunately, my server doesn't allow [R=503] in my .htaccess files. If yours does, and you have mod_headers installed, you might try this, instead:
CODE:
RewriteEngine On
RewriteBase /serendipity
ErrorDocument 503 "Down for maintenance. Check again in an hour.
# Allow blog maintainer back in
RewriteCond %{REMOTE_ADDR} !^your\.IP\.address\.here
# Set environment variable
RewriteRule .* - [E=maintenance:1]
# Add retry timeout if maintenance mode is enabled
Header always set Retry-After "7200" env=maintenance
# Redirect with 503 if maintenance mode is enabled
RewriteCond %{ENV:maintenance} 1
RewriteRule .* - [R=503,L]
That's nicely and fully contained in the .htaccess... if you can get it.