Affiliate Marketing is a major source of income for High Traffic WordPress Blogs/Websites. Users clicks on Affiliate Links, then buys products/services and in turn the Site Webmaster gets paid a certain amount of commission by the Company offering Products/Services.
Affiliate Links can be long and ugly. In this Post we will learn How to Hide/Mask Affiliate Links within your own Blog/Website URL using a very simple PHP Code and by .htaccess File!
An Example
Suppose you have a Blog/Website Address: http://www.xyz.net and you want to hide following Affiliate Link in your Blog/Website:
http://products.com/affiliate/1258787455
Now you want to mask the above affiliate link with a Link (URL) which looks like a part of your Blog’s/Website’s Address:
http://www.xyz.net/products.php or http://www.xyz.net/products
By using PHP Code
All you need is to make use of following PHP Code with the desired affiliate link in it:
<?php header(“location: <Your Affiliate Link Here>“); ?>
Copy the above Code >> Open Notepad >> Paste the above code and Insert the desired affiliate link in it >> Save the file with .php as it’s extension E.g. products.php >> Now Upload this .php File in the Root Directory of your Website using FTP
By using .htaccess File
You can also hide/mask the Affiliate Links using .htaccess file. All you need is to add following lines in your Website’s .htaccess file:
Redirect 301 /products http://products.com/affiliate/1258787455
Above .htaccess Example Code follows the following format:
Redirect 301 /<Term after your Website/Blog URL> http://<Your Affiliate Link Here>
If you want to use PHP Code, than I will personally suggest you to:
- Use target=”_blank”, so that all your Affiliate Links open in New Window
- Use rel=”nofollow”, so that Search Engine Spiders don’t follow/crawl these Redirected Affiliate Links.
Now using above, everytime someone clicks on http://www.xyz.net/products.php or http://www.xyz.net/products, he/she will be redirected to the Website contained in the Affiliate Link.
Hope this Helps lots of Webmasters who want to mask Affiliate Links in their Website/Blog.
Also See: How to Add Google Custom Search in your WordPress Blog’s 404 Not Found Page and Insert Advertisement Code in between Header and Posts in WordPress


What’s the big advantage of this ? Ultimately the user knows that it’s an affiliate link.
Hello Friend,
Thanks for the comment
The main intention behind this Post is to know How Webmasters can Mask Affiliate Links within their own blog/website URL? Instead of giving Long and Ugly Affiliate/Referral URLs, one can easily mask these Links using .htaccess file and simple PHP Code, so that the URL looks like a Part of Website/Blog.
People like us first see the URL of such links before clicking, but there are many people who just click links and buys products/services without thinking that the Source Website, from where they have arrived, is earning commissions from it.
Even if the Masked Link is redirecting to some other site, people buys products and services because they might also be getting some discounts/benefits due to such links