How to Protect Affiliate Links Manually
6 Jan 2013
If you are tired of using a WordPress plugin to protect your affiliate links and want to do it your way, then this article will teach you how to cloak affiliate links manually.
I promise this will be easy. In fact, if you can do a simple copy and paste, then you can follow these steps easily.
This procedure uses clean and simple program using PHP script, but powerful enough to protect your raw affiliate links even create beautiful links that your readers will like.
The whole procedure will give a server-side 301 redirect, which is more search engine friendly.
Ready to bring out the programmer in you? Let’s get started…
Step 1: Create a new folder (or directory) in your html (or public_html) directory. You can use attractive folder names, such as, go, recommend, likes, or refer. Your directory destination should appear something like this:
(using our site as an example).
Step 2: Create a new directory within the directory you’ve just created in step 1. You will use this directory to store the PHP codes that will cloak the affiliate link of the product you wish to promote. Example if you are promoting StudioPress, the directory you should create here is also “studiopress”.
Your directory destination should appear something like this:
(using our site as an example).
Step 3: Create index.php inside the product directory you’ve just created in step 2 (in this case, it’s studiopress directory).
Now, the next step is the coding part.
Step 4: View and edit the index.php file you’ve just created in step 3, then paste these PHP codes:
header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: YOUR AFFILIATE LINK”);
?>
make sure to replace YOUR AFFILIATE LINK with the affiliate link of your product, and see to it that your web browser doesn’t change the double quotes (you can also use single quote if you want).
Step 5: Save your work.
That’s it.
So, were you able to follow through and apply these steps successfully? Feel free to ask for assistance in case you need it. We’re here to help.
→ Subscribe to Blog Via Email to receive updates directly to your email.

Jan 08, 2013 @ 00:48:31
Interesting page. Didn’t know PHP could do it.
Jan 08, 2013 @ 00:54:22
Been looking for this one. Thanks
Jan 08, 2013 @ 06:32:44
Hello and welcome. I’m glad you found this page.
Jan 08, 2013 @ 01:11:37
I like your post but my concern is how to track my click-throughs.
Jan 08, 2013 @ 06:13:37
Hi Dave. A plugin can easily do it, however, most affiliate programs keep track of their click-throughs also, which is found in your affiliate dashboard when you log in.