I read a post by Jonathan Leger today about the SEO benefits of an affiliate program, in which he recommends that merchants do a permanent redirect from the page their affiliates link to to their sales page (for example, from http://www.geckotribe.com/rss/carp/?assoc=1 to http://www.geckotribe.com/rss/carp/ -- ie., just remove the affiliate ID).

The idea is sound, but two headers need to be added to his sample code.

First, the way his sample code was written, it would actually do a 302 (temporary) redirect, since that's what PHP does by default. See my revised sample code below for how to fix that.

Second, there is a small potential downside for affiliates when merchants use 301 (permanent) redirects instead of 302s (temporary) -- let's say someone clicks your affiliate link and the merchant uses a 301 redirect to remove your affiliate id from the browser's address bar. A cookie gets set, and if the customer buys before the cookie expires, the affiliate gets the commission.

But if they wait a while and the cookie expires, and later click your affiliate link again, the web browser will find the permanent redirect in its history file and go straight to the final destination URL without the affiliate ID. So no cookie and no commission.

ClickBank's system suggests the solution to the problem. They use a 301 redirect to redirect a hoplink to the merchant's server. You might think that would result in commission, but it won't, because they also send an Expires header like this:

Expires: 0

What that means is that the 301 redirect should expire immediately! So the search engines will treat it as a permanent redirect and pass all the "link love" on to the website that the redirect points to, but the web browser won't cache the redirect. So if the affiliate link gets clicked again, the browser will still hit the page that sets the affiliate's cookie.

Reader Comment:
Antone Roundy said:
If the document containing the code above also contains the sales letter, then you need to add "exit" inside the curly braces and can remove the "readfile" call. But if the document contains nothing but the code shown above, you use "readfile" to dis...
(join the conversation below)

Here's the revised sample code that does a 301 redirect and causes it to expire immediately (and removes some unnecessary "exit"s):

<?php
if (isset($_GET["hop"])) {
   header("HTTP/1.1 301 Moved Permanently");
   header("Location: http://theproductdomain.com/");
   header("Expires: 0");
} else readfile("salesletter.html");
?>

One technical note: the Expires header is supposed to contain a date in the format "Thu, 01 Dec 1994 16:00:00 GMT", so the value "0" is technically invalid. However, the specification for the Expires header states:

HTTP/1.1 clients and caches MUST treat other invalid date formats, especially including the value "0", as in the past (i.e., "already expired").

So even though it's invalid, it will have the desired effect.