C and S Design.
Search Friendly Programming and Design

Go to -> C and S Design -> Articles -> Code -> ASP -> Redirect Affiliate Links -> Show Code

Click here to view or download the code for this example



ASP Code Articles

Redirecting (Masking) Affiliate Links

Affiliate Links

Something that concerns many website operators and owners are affiliate links and whether search engines "penalise" webpages where the operator/owner uses affiliate programs to generate an income.
The simple answer is; No they don't. But having pages that are all affiliate products and links does mean you have to work a little harder than putting it on line and getting some links to the page.

What are Affiliate Links?

Affiliate links are simply hyperlinks with maybe a product reference code and affiliate ID in the querystring, that takes the user to another site where they can sign up for a service or purchase a product. The referring affiliate then gets paid a fixed fee or a percentage of the sale value.

Where to find Affiliate Programs?

There are many high profile sites that offer perfectly legitimate means where an webmaster can earn money by sending visitors to other sites to make a purchase or to convert in whatever way the target site defines. This may be signing up for a newsletter, adding their name to a contact list for insurance selling, filling in a credit card application and so on.
Amazon with a wide range of products, Ebay have a system called Auction Ads which will show relevant auctions links on your pages, Clickbank ( «« that's a referral link) which has a extensive list of digital products available and Commission Junction

There are also many many more affiliate programs available, that cover the entire range of sites that are on the internet. Online Casinos, Dating sites, Escorts, Hotels, Airlines, Flowers, Gifts, eCards, Lingerie, Adult Material, Online Games, Software Houses, Directories, Lead generators for Financial sites etc etc. So somewhere there is one (or more) that will suit your site topic.
There are also hundreds of schemes such as "turnkey sites", these are where you buy a ready built site, the affiliate account and often the hosting to go with it, these are often oversold with the "Everything you need to make a living on-line!" sales pitch
Unfortunately they all too rarely are!

Affiliate Links are Bad Karma?

Affiliate links and sites that display them are usually (undeservedly) given a hard time in the SEO world, and often get labeled as the fabled "bad neighbourhoods". This is mainly due to people signing up for the aforementioned "turnkey sites" without really knowing how to make them work or being unable to make the changes required to get rid of the boiler plate text that almost every other site that has ever been sold uses.
Because of this duplication, these pages get filtered out of the search engines and as these are all affiliate links for the products, it is usually assumed that it is the affiliate links that has caused its demise.
Yahoo! is particularly good (and quick)at removing sites that are all affiliate. Not because they are affiliates, but because as duplicate pages, they add nothing unique or useful (from the SE point of view) to their index.

The same is true of people signing up for affiliate programs and using the standard text produced by the advertiser on their own pages. This would be acceptable if were there only a few dozen of affiliates for the product, but when there are hundreds or thousands or hundreds of thousands, the situation is somewhat different.
Obviously all those pages cannot be on the first few pages of any search engine so the smart affiliate has to do something different.
Step one of course is to rewrite the text for the product and make it unique, or at least make it radically different from the standard. Make the page title and meta description is attractive to users. If there is an image that goes with the product, change the alt attribute text. Link to the pages from your site navigation using appropriate anchor text. Basically optimise your page for someone elses product.
Step two is to make it appear as if they are NOT affiliate links, and this is where this code comes into play.

Mask the Links

Affiliate links are often a very long curious looking string of characters ( pg=~~4/r=1503/m=2236834/q=n/k=563e6acb3c9b4c02cdcbd568f99603d6/dl=1 for example). Not very good if you want people to link to YOUR affiliate page. So, we need to shorten it and here we can use the same trick as the "URL shortening" sites such as TinyURL use, and that is a server side redirect.

Redirection or Misdirection?

As affiliate links should be about conversions and sales, not about search engine value we can use a HTTP 302 (Temporary Redirect) response, and before anyone berates me for using SE trickery or anything like that, it is perfectly correct, as the link may not always point to the same product or sales site.

The Code

Click to see the PHP Code Version

<%
dim destname
destname = lcase(request.querystring("name"))

' Initialise a variable and get the value of the querystring name key

dim Dests
set Dests = server.CreateObject("Scripting.Dictionary")

' Initialise a variable and Create a dictionary object to hold the values

' Add the keynames and destination URL values to the dictionary

Dests.add "crams","http://www.cram-system.com"
Dests.add "amazon","http://www.amazon.co.uk"
Dests.add "ebay","http://www.ebay.co.uk"
Dests.add "clickbank","http://57erd.reseller.hop.clickbank.net"
Dests.add "auctads","http://www.auctionads.com/"
Dests.add "cj","http://www.cj.com/"
Dests.add "yahoo","http://www.yahoo.com/"
Dests.add "goog","http://www.google.com/"
Dests.add "msn","http://www.msn.com/"


' Code can be inserted in here to log the clickthrough into a database

dim location
location = Dests(destname)
set Dests = nothing

' transfer the location to a variable and
' destroy the dictionary object to release the memory
' before the redirect occurs

response.status = "302 Object Moved"
'response.status = "301 Moved Permanently"

' set the type of redirect required

response.addheader "Location", Dests(destname)

' Send the user off to the affiliate page

%>

Click to see the PHP Code Version

Code Walkthrough

First off we initialise a variable and set it to the value from the querystring key of "name", then set another variable as a dictionary object. The dictionary is then populated with some key/value pairs.
The dictionary object in vBscript works like an associative array, where you can call an item by the key name and get back the value associated with it.
eg:variable = objectName(keyname)
Here the key names are same as the values you would send in the querystring, so to retrieve the destination URL we use location = Dests(destname)
Once we have got the destination URL into the variable, the dictionary object should be set to nothing before calling the redirect, otherwise the object could remain in memory until the session had timed out just occupying server memory.
The final part of the operation is to set the type of redirect to be used by choosing the response code (301 or 302) and then triggering the redirect by setting the Location header for the response to the requesting user agent. End users will not notice any delay while this all this is going on server side and will only know they have clicked a link and ended up on a site where they can buy the product they were interested in.

For this example, using a small number of redirects or for a real world application where a smallish number of redirects are needed, a dictionary is ideal. However, once you get beyond the 50 to 100 mark, the management of the links would become unweildy and using a database to manage them would make more sense.
Added to this, a database would allow you to count the "clicks" on each link to track what products are more popular.

Other Possible Uses for the code

This same code could be put to use in a few different situations:

For Example:-
Directories and Link Pages
Using a "jump" redirect on the entries in the directory will allow for tracking to be added directly to the links. So users and site owners can see directly how popular (or not) your directory is.
If you want to allow the Internet search engines such as Google, Yahoo! or MSN to see the redirected link as a "vote" for the target page, a 301 permanent redirect MUST be used. Otherwise a 302 or a 301 could be used.
Paid Text Links (Sponsored Advertising)
If you sell text link advertising or "Sponsored Links" on your pages, using redirects is a good way to stop search engines seeing them as a "vote" for the target page. It is also a better way than the somewhat ambiguous way that the rel="nofollow" attribute is handled by the different search engines.

More on Paid Links

Google in particular are very much against "Paid Text Links" that are there simply to boost PageRank™ or to push a pages SERP ranking. Pages that are flagged as selling links seem to be given a negative value added to the overall ranking score. For many pages this may be enough to reduce the SERP position of that page and if that page happens to be the "Home" page this value will then "knock on" to the other pages in the site. A way to combat this is to use this redirect method and exclude the "jump" page from the SE bots with robots.txt. This will prevent the search engines from indexing the redirect page thus preventing the final destination from having any value passed on to it.


Valid HTML 4.01! Valid CSS! copyright © C and S Design 2004 - 2005
Website Design and SE Friendly Coding C and S Design