How to cloak your affiliate links – Yoast
Home » SEO blog » Technical SEO » How to cloak your affiliate links
We used to consult for sites that monetize, in part, with affiliate links. We normally advised people to redirect affiliate links. In the past, we noticed that there wasn’t a proper script available online that could handle this for us, so we created one to tackle this problem. In this post, I explain how you can get your hands on it and how you can get it running on your website.
Why should I cloak my affiliate links?
A quick online search will result in tons of reasons as to why you should redirect your affiliate links. The “historical” reason for this is hiding from search engines that you’re an affiliate. It would be naive to think that search engines don’t understand what’s happening, but nevertheless, this seems like a valid reason.
There are also a few more advantages to cloaking your affiliate links, such as:
Ease of management
Sometimes you might need to change your affiliate links. If said links are spread out across your blog, this could become a quite time-intensive task. By centralizing the affiliate links, you have one location to manage all of events leaking PageRank to advertisers
Affiliate links are ads and should be nofollowed or otherwise altered to prevent leaking PageRank to the advertiser. Instead of having to do this manually for every individual affiliate link, you can do this is a single location without much hassle. This also prevents the possibility of forgetting to add nofollow to one of the links. “Clean” links
Different affiliate programs tend to use different permalink structures. Some might have relatively ‘clean’ links, whereas others tend to add a lot of gibberish. Using the redirect script can help you deal with this issue because the cloaked URL will always follow the same structure. This makes it a lot clearer for the user where the link is taking them to!
Cloaking affiliate links, the how-to
The basic process of cloaking affiliate links is simple:
Create a folder from where you’ll serve your redirects. At Yoast, we use /out/ the /out/ folder in your file by adding: Disallow: /out/ Use a script in your redirect folder to redirect to your affiliate URLs.
Step 2 ensures search engines won’t follow the redirects, but we’ll add some extra security measures in our script to prevent accidental indexing of our affiliate links. Step 3 is as easy as manually adding each redirect to your redirect directory’s. htaccess file, assuming you’re running your website on an Apache-based server. Alternatively, you can use the script we produced to make it easier on yourself. The added bonus of this script is that it also works for servers running Nginx!
Affiliate link redirect script
The script we created consists of three files, one of which is optional: an file, a file and, to finish it all off, a. htaccess file to prettify your URLs.
This file contains the logic that handles the actual redirection by performing a 302 redirect. Additionally, it sends a X-Robots-Tag header along to ensure search engines that can detect this header, obey the noindex, nofollow rules we pass along in it. We do this as an extra security measure in case you might forget to exclude the affiliate link in your
The file is a comma-separated file that contains a list of names and destination URLs like so:
Note that the file should always contain the following line at the very top to ensure people don’t attempt to redirect themselves to a non-existing URL:
Just change to your own domain and you’re ready to go!. htaccess
If you only install the above two files, you’ll already have enough in place to get things running. However, we advise you prettify the URLs because this dramatically increases the readability. Without prettifying your URLs, you’ll end up with something like /out/? id=yoast instead of /out/yoast.
Prettifying can be achieved by adding a. htaccess file to the mix. This small file also helps ensure people can’t access your file to take a peek and see what affiliate links are available.
What about plugins?
In the past, we’ve received questions about using WordPress plugins to tackle this cloaking issue. Despite there being a lot of valid options, they have one small caveat: speed. Because these plugins depend on WordPress’ core code, they need to wait for it to be fully booted before being able to execute themselves. This can easily add a second or two to the total loading and redirecting time if you’re on a slow server. Our non-plugin solution is faster because it doesn’t depend on WordPress to run.
Ultimately, the best option depends on your needs. If you want to collect statistics on your affiliate links, you might be better off with a plugin. Otherwise, just use our script to keep things fast.
If you’re interested in running this nifty script on your own website, you can download the files. Feeling adventurous? You can find the source code on GitHub. People running Nginx can find sample code in this gist to see how to make it work for them.
Read more: Playing with the X-Robots-Tag HTTP header »
Joost de Valk is the founder and Chief Product Officer of Yoast. He’s an internet entrepreneur, who next to founding Yoast has invested in and advised several startups. His main expertise is open source software development and digital marketing.
Affiliate Marketing: Should You Cloak Your Affiliate Links? – InterServer
When researching affiliate marketing strategies, you may come across link cloaking. Countless affiliate marketers use this strategy to mask the destination of their affiliate links. Cloaking allows affiliate marketers to create and use their own custom links, which redirect users to their affiliate products.
Being that it shows users a different destination than the link’s actual destination, you might be hesitant to cloak your affiliate links, fearing it will lead to fewer sales or conversions. Cloaking your affiliate links, however, will almost always have a positive impact on your affiliate marketing efforts. On the topic of affiliate programs if you are interested in promoting InterServer web hosting and getting paid $100 per sale please consider our web hosting affiliate program.
What Is Cloaking?
Cloaking, when used in the context of link building, involves the use of a redirect to conceal the destination of a link. Also known as link masking, it replaces the visible destination URL of a link with a custom-created destination URL. When a user clicks on a cloaked affiliate link, his or her web browser will load the custom-created destination URL, at which point the user will be redirected to the real destination URL as specified in the affiliate link.
Here’s a comparison of a conventional affiliate link versus a cloaked affiliate link:
Conventional Affiliate Link:;affiliate=184750
Cloaked Affiliate Link:
Cloaking isn’t considered black hat, nor will it leave your affiliate account vulnerable to suspension or termination. Nearly all affiliate marketing networks allow or even encourage affiliates to cloak their links. It’s a simple process that involves creating a new web page with a redirect to the destination URL of an affiliate link.
Benefits of Cloaking Your Affiliate Links
Cloaked affiliate links are more appealing than conventional affiliate links. As shown above, conventional affiliate links typically consist of long strings of letters, numbers and special characters. Because of their generic and non descriptive appearance, they don’t attract as many clicks as cloaked affiliate links.
When you cloak an affiliate link, you’ll have the freedom to change the destination URL so that it’s more appealing. You aren’t required to promote the unsightly affiliate links provided by the affiliate marketing network. Instead, you can cloak them. Once cloaked, your affiliate links will shorter and more descriptive, which should compel more users to click them. As a result, cloaking your affiliate links can drive higher click-through rates (CTRs) as well as more sales or conversions.
You can rest assured knowing that cloaked affiliate links are protected against malware-related link hijacking. Villainous affiliate marketers use malware to steal the commissions of hardworking affiliate marketers. They distribute malware that, once on a victim’s computer, automatically replaces other marketers’ affiliate links with their own affiliate links. The malware uses a link hijacking script to replace affiliates links viewed on the victim’s computer.
Link hijacking scripts work by scanning links for the footprints of an affiliate marketing network. If the script detects a link from an affiliate marketing network, it will replace it with the nefarious marketer’s own affiliate link. Thankfully, cloaked links are naturally protected against malware-related link hijacking such as this. Link hijacking scripts only look for conventional, uncloaked links, so you won’t lose any commissions from this nefarious tactic.
Statistics show nearly one in three internet users now have an ad blocker extension or plugin installed on their web browser. While ad blockers clean up a lot of spam, they often target legitimate ads, including those containing affiliate links. If you publish a banner ad using a conventional affiliate link, users with an ad blocker may not see it. Ad blockers will block ads containing links used by affiliate networks. And if a user doesn’t see an ad, he or she won’t be able to click it.
Finally, you’ll be able to track engagement signals more closely by cloaking your affiliate links. Affiliate networks offer their own tracking solutions, but they only track the total number of clicks and conversions an affiliate link generates. If you want to promote an affiliate link on three different channels, you won’t be able to tell which channel drove the most traffic. You can track clicks across multiple channels by cloaking your affiliate links. When promoting
an affiliate link on three different channels, simply create three cloaked links. Each of the cloaked links should have a unique filename, but they should all have the same redirect code pointing to your affiliate link. Once deployed in your affiliate marketing campaign, you can track how many clicks each of the three cloaked links generated to determine which channel drove the most traffic.
According to Search Engine Land, cloaking affiliate links in landing pages can lead to higher Quality Scores in pay-per-click (PPC) advertising campaigns. If Google or Bing detects affiliate links in your pages, they may impose lower Quality Scores on your target keywords. Of course, you can conceal your affiliate links, and therefore earn higher Quality Score by cloaking them.
How to Cloak Your Affiliate Links
There are several ways to cloak an affiliate link, one of which is to create a PHP file with a header redirect. Just create a new PHP file — you can create PHP files using Microsoft Notepad – – and add the following code to it:
php header( ‘Location: [enter your affiliate link here]’);? >
After adding the header redirect code, save the PHP file with the name that you’d like users to see when hovering over the cloaked affiliate link, such as You can then upload the PHP file to your website’s root folder. To ensure it works, try accessing the PHP file on your web browser. Visiting the location of the PHP file, such as should redirect you to your affiliate link. If you use WordPress, you can download a plugin to cloak affiliate links published on your website. Available at, the ThirstyAffiliates plugin adds a link cloaking feature to WordPress websites. Another link cloaking plugin available for WordPress is the aptly named Pretty Links. Available at, it allows you to quickly and easily cloak your affiliate links. To succeed with affiliate marketing, you must publish links to your affiliate products. But whether you publish them on your website, blog, social media profiles or elsewhere, you should consider cloaking all your affiliate links.
How to Make Your Affiliate Links No Follow (And Stay on Google’s Good …
This post contains affiliate links which means if you click on a link and choose to make a purchase I will receive a commission at no additional cost to you. See our disclaimer for more a blogger it is important to look for different ways to monetize your blog. One of the best ways to start monetizing your blog is through affiliate marketing.
Your job as an affiliate marketer is to create helpful content and link to relevant affiliate products within your blog posts. When someone click on your affiliate link a “cookie” is stored in their browser with your unique affiliate id and when they go to make a purchase the sale is attributed to your affiliate id and you can make a commission off of their purchase.
This sounds great right?
All you have to do is promote products and make money! Sounds like a pretty sweet gig!
A little caution before you jump right in and start adding affiliate links to all of your posts.
You should know that affiliate marketing isn’t as easy as just slapping a few links within your blog posts and making money. There is definitely an art to affiliate marketing. Sometimes the tricky part is figuring out how to sell to your readers without coming across as too pushy. If you are new to affiliate marketing and ready to get started this course on affiliate marketing offers a great foundation on setting your blog up for success with affiliate marketing.
On the other hand if you have been using affiliate marketing for a while, but feel you are just not making any significant progress then this course offers more advanced affiliate marketing strategies especially when it comes to being effective with email marketing and using affiliate links (although I would still recommend it to beginner affiliate marketers).
Now before you start adding affiliate links to your blog there are a couple of best practices that you should be aware of when using affiliate links. Keep reading to learn about the 3 things you should do with every affiliate post and specifically how to make your affiliate links no follow to stay on Google’s good list.
Make sure you Pin it and SAVE this post for later if you don’t have time now.
1. Make your affiliate links no follow
With every affiliate link you create you should make it a no follow link.
What is the difference between a “do follow” and a “no follow” link?
The distinction between a “do follow” link and a “no follow” link has to do with Google and how they crawl your website and link you to other websites.
One of the ranking factors Google uses to determine where you rank in search results is your authority and the quantity and quality of websites that link to your content (i. e. backlinks). A good backlink is one that comes naturally where another website decides to link to your content because your post offered relevant information to their reader (Google would consider this a do follow link).
When you add an affiliate link to another website this is NOT a natural link. Because you have “financial motive” behind that link you need to let Google know that they shouldn’t follow this link or count it as a backlink for that website.
How to make an affiliate link no follow
To make a link no follow you need to add additional html code: rel=”nofollow” to your affiliate link. When creating your post in WordPress in the classic editor you need to click on the text editor to modify the html code for your page.
With the new Gutenberg editor you will click on the three dots for more options.
From the options select Edit as HTML.
Here is an example of the html for a normal link:
Find helpful blogging tips here
Here is an example of the html for a no follow link:
Find helpful blogging tips here
You will notice that I added rel=”nofollow” in the code after target=”_blank”. The target attribute is used when you want to open the link in a new window and you can select this option when adding the link in WordPress. Just place the rel=”nofollow” code after this.
How to make an affiliate link no follow using a plugin
If you don’t want to mess with adding the code manually each time for every affiliate link you can use the rel nofollow checkbox plugin.
When you go to add a link to your post click on the link icon and then select the gear icon to see the link details.
The plugin adds a checkbox with rel=”nofollow”. Each time you create an affiliate link check this box and then you don’t have to mess with adding any code manually.
2. Add and affiliate disclaimer to your blog post
Before including any affiliate links you need to include an affiliate disclaimer. An affiliate disclaimer is a simple statement that lets your audience know that you could be compensated if they click on your link. The FTC (federal trade commission) requires that this statement appear before any affiliate links are used on the page.
One way your reader may interpret this statement is that you may be recommending these products because you want to get paid not just because you think it is the best product for them. This is usually not the case, but this is why you need to include an affiliate disclaimer because your audience needs to know that you might just be recommending this products for financial gain. I do not recommend this. Make sure you are recommending good products that can actually benefit your readers.
With the affiliate disclaimer you want to make it clear to your audience that the post contains affiliate links and that you may receive a commission if they click on the link.
Here is an example of my affiliate disclaimer:
At a minimum you need to acknowledge that the post contains affiliate links and then in my case I have chosen to direct the reader to my affiliate disclaimer page where I go into more detail about what this means.
How to add an affiliate disclaimer to your blog post
There are a couple of ways you can add an affiliate disclaimer to your blog post. You could choose to manually place it where you want it to appear in each blog post or you can use a plugin. I initially started doing it the manual way, but then I decided I wanted to streamline my process with a plugin and not have to add the same bit of text each time to every blog post.
How to add an affiliate disclaimer using the FMTC affiliate plugin
In your WordPress dashboard click on Plugins from the left hand menu. Click to add a new plugin and search for FMTC Affiliate Disclosure plugin.
After the plugin is installed and activated go to settings in the left menu and select affiliate disclosure.
They have a default statement you can use, but you have the ability to modify it and add html. If you want to link to your affiliate disclaimer page then you will want to add html code specifically the tag (anchor tag) to allow for a clickable link.
Here is an example of the code:
This post contains affiliate links. See our disclaimer for more information.
3. Use advanced tracking links
This final piece of advice separates the newbie from the experienced affiliate marketer. Make sure you use advanced tracking links with your affiliate links.
What is an advanced tracking link?
Not every affiliate program may give you the option, but an advanced tracking link is a customized link that you can create to help you understand where your conversions are coming from. If you are promoting Product A in 3 different blog posts you should create a different custom link for post A, post B and post C. As you begin to make sales you can see where your conversions are coming from.
Create a system from the beginning
As you create these advanced tracking links make sure you have a naming system in place that you can understand. For every one of my blog posts I have assigned a post ID number. When I go to create my customized link I include that post ID. This way in the conversion report I can understand what blog post the link came from that they clicked. Ultimately you want to see if one blog post converts better than another.
How to create a custom link with Amazon Associates
Amazon Associates is a popular affiliate program for bloggers. (let’s be honest it is really easy to link to them because they have a wide variety of product selection). When you use an amazon affiliate link in your blog post you should create a unique product link for each blog post. This way you can understand where your conversions are coming from.
After logging into your Amazon Associates account click on Product Linking and select Link to Any Page from the drop down menu.
Next enter the URL of the product you want to link to and name your link. This is where you will use your special naming convention that helps you understand where this link will go. Click on get HTML to get your unique affiliate link.
I know this requires some extra work on your part, but it will be worth it. Having the knowledge of knowing what blog posts are converting and which aren’t can help guide your strategy and understanding your ROI (return on investment).
I hope you found this post helpful and that you feel a little more comfortable with affiliate marketing. If you want to learn more about affiliate marketing I highly recommend this course to get your foundation going with affiliate marketing and this course if you want more advanced affiliate marketing strategies.
Looking for more tips on how to monetize your blog?
Check out this post on how to make money online with a blog where I discuss the 8 most common ways to monetize your blog.
Check out this post on how to start affiliate marketing for the newbie blogger who has no clue where to start
Hi! I’m Tricia the founder of Blog Her Way. I teach aspiring bloggers how to set up their website + grow their email list to start earning income online.
Frequently Asked Questions about how to mask affiliate links
Should you cloak your affiliate links?
Cloaking allows affiliate marketers to create and use their own custom links, which redirect users to their affiliate products. Being that it shows users a different destination than the link’s actual destination, you might be hesitant to cloak your affiliate links, fearing it will lead to fewer sales or conversions.Dec 3, 2019
How do I cloak affiliate links for free?
To make a link no follow you need to add additional html code: rel=”nofollow” to your affiliate link.Oct 29, 2018