Hey everyone, as you can see i'm new here.. i just joined today. I usually hang out in the WMR irc chat but a friend convinced me to give this a shot as well=) Anyway i thought i would just share a tutorial i just wrote on how to redirect and cloak links which includes how to build a php redirect script to mask all of your affiliate links. You can find the original source on my blog located here - A Complete Guide to Link Redirection and Cloaking » Kevin B Fleming - Internet Entrepreneur
A Complete Guide to Link Redirection and Cloaking
Link Redirection which is also sometimes referred to as link cloaking is very useful for many things, some completely legitimate, and others not so legitimate.. however to many people redirection can be confusing, not necessarily because it’s hard, usually because there are just so may different ways to do it.
This guide covers four different ways to redirect a page… using PHP, JavaScript, .htaccess, and a Meta Refresh tag. It will also explain which methods are search engine friendly, and the best way to cloak a link for affiliate marketing and PPC purposes.
1. PHP Redirect
Most people like using PHP, because there is a ton you can do with it, and its processed on the server before it reaches the users browser, resulting in a very quick and search engine friendly redirect.
PHP redirection is what I personally use, mainly because of its flexibility. As you can see by the sample code below, redirecting with PHP is extremely simple and really just consists of 3 elements - An opening PHP tag, a location you want the page to be redirected too, and a closing tag.
When someone trys to access the page that the code below is placed on, they will be automatically redirected to the URL specified in the code.
It’s important to remember to not have any text before this script or it won’t work. I would not recommend including an additional content besides the script above on the redirect page.
You can download the php file here.
2. Advanced PHP Link Cloaking
Above I mentioned how I like using the PHP method because of the flexibility. Well now I’m going to show you how to build a more advanced link redirect system that you can use with multiple links. This is a perfect solution for affiliate marketing and PPC links.
First you will need to create a new PHP file…in this case i named it link.php.
Then as you can see below you need to include this simple script in which each if statement is a different page you want to redirect. This method is widely used in affiliate marketing because you can mask all your affiliate links using this one file and your URLS will then look like this…http://www.yoursite.com/link.php?dating - which would redirect to the dating url.
You can download the php file here
3. JavaScript Redirects
A JavaScript redirect is very simple to do because it can be done with just one line of code, as seen below. I don’t think this really needs any further explanation.
4. .htacces Redirects
I could probably write a whole guide in itself on the different ways you can use .htaccess redirects, however below are 3 different things you can use .htaccess redirection for. Like PHP using a .htaccess redirect is great because there is no delay since your browser checks the .htaccess file before it even checks the destination of the url. This type of redirection will not work on windows servers, and ALWAYS upload .htaccess files in ascii mode or else you can mess up your server, YOU HAVE BEEN WARNED.
Basicly all you need to do is create a file named .htaccess using a text editor like notepad, include the specied code below and then upload the .htaccess to the particular folder on your server your webpage or site is in. This method is very search engine friendly.
Move a Single Page:
Move a Site:
Changed File Extention:
5. Meta Refresh URL Redirect
This is a very simple redirect that you include in the meta data of a page. Honestly I would not recommend using this type of redirect, using a PHP redirect is far more Search Engine friendly but regardless, some people still use this. All you need to do is copy and paste the code below into a pages META Data and replace the URL with the URL of the page the visitor should be redirected to. The number before the URL is the time (in seconds) you want the browser to wait before redirecting the visitor.
A Complete Guide to Link Redirection and Cloaking
Link Redirection which is also sometimes referred to as link cloaking is very useful for many things, some completely legitimate, and others not so legitimate.. however to many people redirection can be confusing, not necessarily because it’s hard, usually because there are just so may different ways to do it.
This guide covers four different ways to redirect a page… using PHP, JavaScript, .htaccess, and a Meta Refresh tag. It will also explain which methods are search engine friendly, and the best way to cloak a link for affiliate marketing and PPC purposes.
1. PHP Redirect
Most people like using PHP, because there is a ton you can do with it, and its processed on the server before it reaches the users browser, resulting in a very quick and search engine friendly redirect.
PHP redirection is what I personally use, mainly because of its flexibility. As you can see by the sample code below, redirecting with PHP is extremely simple and really just consists of 3 elements - An opening PHP tag, a location you want the page to be redirected too, and a closing tag.
When someone trys to access the page that the code below is placed on, they will be automatically redirected to the URL specified in the code.

It’s important to remember to not have any text before this script or it won’t work. I would not recommend including an additional content besides the script above on the redirect page.
You can download the php file here.
2. Advanced PHP Link Cloaking
Above I mentioned how I like using the PHP method because of the flexibility. Well now I’m going to show you how to build a more advanced link redirect system that you can use with multiple links. This is a perfect solution for affiliate marketing and PPC links.
First you will need to create a new PHP file…in this case i named it link.php.
Then as you can see below you need to include this simple script in which each if statement is a different page you want to redirect. This method is widely used in affiliate marketing because you can mask all your affiliate links using this one file and your URLS will then look like this…http://www.yoursite.com/link.php?dating - which would redirect to the dating url.

You can download the php file here
3. JavaScript Redirects
A JavaScript redirect is very simple to do because it can be done with just one line of code, as seen below. I don’t think this really needs any further explanation.
Code:
<script type="text/javascript">document.location.href=’www.yoursite.com’</script>
4. .htacces Redirects
I could probably write a whole guide in itself on the different ways you can use .htaccess redirects, however below are 3 different things you can use .htaccess redirection for. Like PHP using a .htaccess redirect is great because there is no delay since your browser checks the .htaccess file before it even checks the destination of the url. This type of redirection will not work on windows servers, and ALWAYS upload .htaccess files in ascii mode or else you can mess up your server, YOU HAVE BEEN WARNED.
Basicly all you need to do is create a file named .htaccess using a text editor like notepad, include the specied code below and then upload the .htaccess to the particular folder on your server your webpage or site is in. This method is very search engine friendly.
Move a Single Page:
Code:
Redirect 301 /old.htm http://www.yoursite.com/new.htm
Move a Site:
Code:
Redirect 301 / http://www.yoursite.com
Changed File Extention:
Code:
RedirectMatch 301 (.*)\.html$ http://www.yoursite.com$1.php
5. Meta Refresh URL Redirect
This is a very simple redirect that you include in the meta data of a page. Honestly I would not recommend using this type of redirect, using a PHP redirect is far more Search Engine friendly but regardless, some people still use this. All you need to do is copy and paste the code below into a pages META Data and replace the URL with the URL of the page the visitor should be redirected to. The number before the URL is the time (in seconds) you want the browser to wait before redirecting the visitor.
Code:
<meta http-equiv="refresh" content="8;url=http://www.yoursite.com" />