Affiliate URL Re-Direct Code

Guard Dog

Guard Dog
Staff member
Joined
Dec 13, 2006
Messages
11,238
Reaction score
3,146
Anyone have any affiliate URL redirection code for me? I'm looking to do something similar to what a lot of sites have whereby I would have the following URL:

http://www.mysite.com/go/casinoguarddog

and it would then redirect to the Casino Guard Dog ™ ** casino and count that click in my database.

** Of course there is no such casino or trademark :)
 

pinkytoe

Affiliate Guard Dog Member
Joined
Apr 11, 2011
Messages
100
Reaction score
26
ugh cant post URLS. Ah well
 

Guard Dog

Guard Dog
Staff member
Joined
Dec 13, 2006
Messages
11,238
Reaction score
3,146
I did get your PM, thanks for that :)

However - I am looking for more of a database-driven example. The thought being this:

1. .htaccess redirect that takes all: http://www.mysite.com/go.php?casinoname and converts to: http://www.mysite.com/go/casinoname/

2. php file that will store clicks into my database

3. php file that will retrieve my affy code for the redirection.


So more of a complete package, IMO.
 

Aussie-Dave

Former AGD Member
Joined
Nov 24, 2007
Messages
684
Reaction score
3
Andy,

Does it have to be database driven?

I have a php script which runs flat files, simple to setup with a compact backend which also count clicks too.

Wouldn't be hard to implement the pretty URL's via .htaccess

Let me know and I can send it over.


Cheers

:)

Dave
 

rak

Affiliate Guard Dog Member
Joined
Dec 2, 2010
Messages
60
Reaction score
2
Anyone have any affiliate URL redirection code for me? I'm looking to do something similar to what a lot of sites have whereby I would have the following URL:

http://www.mysite.com/go/casinoguarddog

and it would then redirect to the Casino Guard Dog ™ ** casino and count that click in my database.

** Of course there is no such casino or trademark :)

Hey Andy, I think I have this coded up and ready for you. If not - I can whip it out in 30 mins. I'm remote at the moment, when I get home - I'll paste the code onto the forums if you dont mind? Might serve other people some use as well?
 

Vladi

Affiliate Guard Dog Member
Joined
Feb 4, 2008
Messages
772
Reaction score
115
Ok. This all assumes you have casinos, poker, bingo rooms etc in your database with a numerical ID for each record.

I like to include a casino id number in the URL as it makes it easier to find the casino you want in your database. Otherwise you're going to be matching strings to casino names which can get ugly if anything changes.

So lets assume the URLs you want to use are like this (linking to the mythical 33 Black Casino which has an ID of 5 in your database):

Code:
www.mysite.com/go/5/33blackcasino

You will need a script that you want to call instead. Lets assume you call it redirect.php and its in a couple of folders off the root of your site like www.mysite.com/path/to/redirect.php

In .htaccess:
Code:
RewriteRule ^go/([0-9]+)/(.*)$ path/to/redirect.php?id=$1&c=$2 [L,NC]

That will transparently catch any requests for one of your links and handle them with your script without the user seeing the URL change in the address bar, like so:

Code:
/path/to/redirect.php?id=5&c=33blackcasino

In redirect.php (I'm not going to do it all for you!):

1. Read the $_GET['id'] parameter, check its a valid integer
2. Get the affiliate URL you need using the ID - either from your database or you could just put them all in redirect.php in an array using the ID number as a key.
3. Log the click to the database if you want.
4. Redirect the user using the affiliate URL like so:
Code:
header("Location:" . $url);

Don't forget to nofollow all your /go links and exclude them from being spidered using robots.txt.

If you have followed along you're probably wondering why I have the casino name in the link at all. You don't need it but it looks nicer to the user and can be useful if you track outbound clicks using google analytics or similar (which you need to do using javascript before the user is redirected to your script).


Bonus tip for advanced players: never ever write an affiliate URL manually in your html or php pages. Create and use a php function that fetches the URL from the database and prints the anchor tag instead. Then next time an affiliate program changes their links in "an upgrade" you'll barely grunt as you spend the 2 minutes required to update your link in the database then get back to work. Or when a program goes rogue its a simple matter of marking them rogue and your link script refuses to print links to them any more. Meanwhile all the other affiliates with 100 sites with hard coded links in thousands of html pages rush to the forums to complain before they spend the next week or two searching for and updating them by hand. ;)
 

Aussie-Dave

Former AGD Member
Joined
Nov 24, 2007
Messages
684
Reaction score
3
Meanwhile all the other affiliates with 100 sites with hard coded links in thousands of html pages rush to the forums to complain before they spend the next week or two searching for and updating them by hand. ;)

Been there done that and I can tell you it's no fun. Worse, most times you end up missing links, which leads to a lot of :emoticon-0127-lipss followed by :emoticon-0179-headb

Been slowly updating everything to a centralised domain just for this purpose.
Seeing your a switched on webmaster Vladi, would using a CDN be of any help (in terms of speeding up things) when feeding all these links, banners and what not from a centralised domain?


Cheers

:)

Dave
 
Last edited:

Vladi

Affiliate Guard Dog Member
Joined
Feb 4, 2008
Messages
772
Reaction score
115
A CDN can definitely help for images, video, css files, javascript etc because it will allow the visitor to download more files at once in parallel, and also in theory the CDN server will be closer and quicker to the visitor than yours. But its only going to be really worthwhile if you have a large amount of traffic or your site is very image or script heavy. It won't do anything for links as they are simple redirects.

If you're using common javascript libraries like jquery, prototype, or mootools etc you can have them served from google's servers instead of your own which is like having a free CDN. It also increases the chance that the visitor will already have the library cached from a previous visit to an unrelated site that used the same library.

For example the latest version of jquery courtesy of google:
https://ajax.googleapis.com/ajax/libs/jquery/1.6.1/jquery.min.js

More info: Google Libraries API - Google Code
 
Top