Apache for Webdesigners

.htaccess for HTMLers

The apache webserver highly end user configurable. This is done on the directory level with .htaccess files.

How do I do this?

Default Images

If in a directory an image is not found a default image shall be delivered. This is done by configuring the default image as an error document in .htaccess.

<Files "*.jpg">
ErrorDocument 404 /path/needed/dflt.jpg
</Files>

The purpose of the Files container is to deliver the default image only for JPEGs. The browser would be correct to be confused if he would get this default image while requesting a GIF.

The method above has the disadvantage of writing 404s to the logfiles. If this is not desirable, mod_rewrite needs to take care of this before the 404 happens.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^.*\.jpg$ dflt.jpg [L]

Marking Documents as Gone

If a document has been removed you will find that search engine bots and the searchers that follow them keep requesting those documents for months (in case you read your logs). If you want the document to be removed from the search engines indexes it makes sense to replace the usual 404 (Not Found) with a 410 (Gone).

RedirectMatch gone ^/webalbum.*

This is admittedly a bit unexpected for a directive named RedirectMatch. Note that the third parameter has been omitted.