Avoiding Link Rot: Redirection

There are a number of ways to notify readers when you have moved. One of the most typical methods is by adding a line in the body of your work like so:

I've moved. Here's where you can find me.

That works, but it requires the reader to do something. Better still is a combination of that method, and the insertion of a meta tag in the head element of the work's HTML, so that the reader will be taken to the new site without clicking the link.

<meta http-equiv="Refresh" content="0; URL=http://www.coxesroost.net/peanuts/" />

This also works, but the reader sees a noticeable delay as the browser loads the page, then refreshes the content from the new address. It also involves a lot of work if you want to refresh each page to its equivalent.

Better yet, and intended for the purpose, is redirection. This feature of HTTP allows the server to tell the client where a thing has gone.

Most web servers allow fine-grained control over redirection. The following examples refer to Apache.

The Apache server configuration can be set either server-wide in the httpd.conf file, or locally, for a specific segment of the filesystem, by the .htaccess file. Assuming you do not have control over the server's configuration files, you want to add a line such as this

Redirect permanent /~cwcjr/radio http://www.coxesroost.net/peanuts
to an existing .htaccess file, or to a new document, which you then save as .htaccess in the directory in or below which you want to effect the change. .htaccess is the default file name used by Apache, but it could be anything.

The RedirectMatch directive makes this more flexible, by using regular expressions. A regular expression is a pattern. This word is a pattern that matches this word. Wildcards, such as *, are patterns that match certain things, such as, in our example, everything. Being able to use these in the RedirectMatch directive reduces the amount of work to match all of the patterns on the site.

So if as parted of your migration, you switched to PNG images instead of GIF, your .htaccess file might look something like this:

Redirect permanent /~cwcjr http://www.coxesroost.net
Redirect permanent /~cwcjr/radio http://www.coxesroost.net/peanuts
Redirect gone /~cwcjr/blogger
RedirectMatch (.*).gif$ http://www.coxesroost.net$1.png
This says, take anything followed by exactly .gif and turn it into http://www.coxesroost.net/theThingMatched.png. Since theThingMatched includes a path element (/), that's not necessary in the replacement pattern.

Next Problem: Getting the .htaccess file to the server.

FTP works, but if you are using a more helpful content management system, such as Radio Userland, it may ignore files which begin with a dot (.). In that case, you must come to some agreement with the server administrator as to whether they'll permit the use of an .htaccess file, and what that file will be named.

References:

The Apache Documentation:
  mod_alias: redirect directive
  Configuration Files
Using .htaccess Files with Apache
Apache: The Definitive Guide, 2nd Edition, Laurie & Laurie (O'Reilly, 1999)

Copyright 2002 © Will Cox.
Last update: 7/18/2002; 4:02:57 PM.