Beware POST Request Redirects

You probably know that you should choose either example.com or www.example.com for your website, but allowing both of these effectively means that you are splitting your search engine ranking in two (if you care about such things). I use Dreamhost and they make it very easy to redirect all traffic to one or the other of these. They do this using a 301 (permanent) redirect. For example, if you type curl http://www.ananelson.com, you will see:

<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<HTML><HEAD>
<TITLE>301 Moved Permanently</TITLE>
</HEAD><BODY>
<H1>Moved Permanently</H1>
The document has moved <A HREF="http://ananelson.com/">here</A>.<P>
</BODY></HTML>

You can easily set this up yourself in your Apache config or a .htaccess file.

Now, something I’ve managed to do twice in the last week is to POST a form to the www-version of my domain, which then was redirected to the non-www version. When this happens, all the POST data is lost! (See the Apache documentation.) So, remember, when creating a form set its action URL to whichever is the preferred variant of your domain name so that no redirect takes place.