Apache is great. My latest discovery is mod_asis, which “provides for sending files which contain their own HTTP headers”. You just put the headers at the top of the file, separated from the content with a blank line.
Status: 200 OK
Content-Type: text/plain; charset=UTF-8
Last-Modified: Wed, 29 Nov 2006 08:12:31 GMT
Hello!
There’s nothing there you can’t do in your programming language of choice, but it’s far more elegant than, say, the PHP equivalent:
<?php
header('HTTP/1.1 200 OK');
header('Content-Type: text/plain; charset=UTF-8');
header('Last-Modified: Wed, 29 Nov 2006 08:12:31 GMT');
?>Hello!
It still seems pretty useless, but there are times when custom headers are important. At the very least, it’s a perfect fit for unit-testing HTTP clients.
For a more common example, consider the simple deletion of a file from a server. If you have no intention of putting it back, requests to that URL should return a status code of 410 (”Gone“), so clients know not to retry the request later. Apache has no mod_psychic to divine the webmaster’s intentions, and will return a less-useful 404 (”Not Found”). It’s a deliberately vague response, because the long-term status of the resource isn’t clear.
With mod_asis you can add index.asis to your DirectoryIndex directive as a drop-in replacement for index.*:
AddHandler send-as-is asis
DirectoryIndex index.html index.php index.asis
Or work some magic with (e.g.) MultiViews. Tada, a 410:
Status: 410 Gone
Content-Type: text/html
<html>
<head>
<title>Content Removed</title>
</head>
<body>
<h1>Content Removed</h1>
<p>Sorry -- this page of saucy H.P. Lovecraft limericks is gone and shan't be coming back. Cthulhu fhtagn!</p>
</body>
</html>
Okay, so in practice there’ll probably be an easier or better way, like Redirect gone or mod_rewrite with the G modifier, or having things handled automatically by your content-management system.
Still, it’s a nice tool, and you can never have too many of those.