How to Cloak Affiliate Links Without Plugin in a WordPress Site?

| | November 14, 2022

In this article you will learn how to cloak affiliate links without plugin on a website using .htaccess redirection

You will also learn why it is important to cloak affiliate links.

When you join an affiliate program as an affiliate, you are provided with a URL containing your unique referral code.

This URL or affiliate link containing your referral code helps in tracking your sales.

Now the question arises what is the need of cloaking affiliate link and what are the best method of doing it.

If you have heard this term cloaking for the first time and what it does, don't worry.

In this article you will lean what is cloaking and how to cloak affiliate links in a WordPress site without any plugin. 

We will use a different technique other than the WordPress plugins to cloak affiliate links. 

So, how we are going to achieve this?

We will cloak affiliate links using .htaccess redirection.

Let's learn more about it in detail in the next section.

Note: This article contains affiliate links. When you click an affiliate link and make a purchase, we get a small compensation at no cost to you. See our Privacy Policy and Disclaimer for more info.

Must Read: A2 Hosting India Review

Why Should You Cloak Affiliate Link?

Every day thousands of blogs are launched around the world.

With increase in number of blogs competition in affiliate marketing has also increased to a great extent.

Every bloggers wants to beat competition and succeed in affiliate marketing.

For achieving success many people resorts to different malpractices to steal off your affiliate sales. 

Many competitors hire companies which through malware tries to replace your unique affiliate links with their own link and earn commissions causing loss to you.

We can tackle these problem by using a technique called Link Cloaking.

What is Affiliate Link Cloaking?

Link cloaking is a technique used for shortening long affiliate links. Usually affiliate links are long and ugly to look. By shortening affiliate link by cloaking it looks branded and also results in higher Click-Through-Rate (CTR).

See this example.

A traditional affiliate link look like this-

We can shorten the above link by using link cloaking method to make it look like a branded URL as shown below-

Benefits of Using Link Cloaking

  • As mentioned above link cloaking shortens the affiliate link and the link looks more branded to your user. Users  are now more likely to click on this branded URL instead of long affiliate link thereby increasing the click-through rate (CTR).
  • By using link cloaking it becomes difficult for anyone to use malware to replace your unique affiliate link. Thus, you preserve your commission.
  • Now you can easily manage all your affiliate links by placing all of them under one folder.
  • If you actively promote your affiliate campaign by sending emails to your users then it would be wise to cloak your affiliate link in order to land your mails in inbox folder instead of spam folder.

How to Cloak Affiliate Links using .htaccess redirection?

STEP 1: Decide on your URL slug

You can use any of these URL slug, for example,


  • /affiliate/, 
  • /go/,
  • /refer/,
  • /out/ or
  • /recommended/

To do this you will need to create a folder in your root directory. Just login to your cPanel and create a folder (select any one of the above example), for example, 'go' under public_html folder.

Now your affiliate link will look like this-

STEP 2: Prepare Related URL

In this step you will need to compile a list of related URL for all your affiliate links.

For example, if your affiliate link is

Now you need to create related URL for above affiliate link as shown below.

Repeat the same process for all of your affiliate links.

STEP 3: Modify .htaccess File

In this step we will have to modify the .htaccess file which is located under public_html folder. 

If you are not seeing it then it might be possible that the file is kept hidden by default. 

You can see the hidden .htaccess file by selecting Settings in File Manager.

Here, you have to select the check box with the option Show Hidden Files (dotfiles). See the image given below.

Enable hidden files in File Manager

Enable hidden files in File Manager

.htaccess file

.htaccess file

Note: Whenever you modify the .htaccess file always make it a habit to keep a copy of it at a safe place in case something goes wrong.

Now open the .htaccess file and add all the affiliate links as shown below-


Redirect 302 /go/bluehost

Redirect 302 /go/siteground

Redirect 302 /go/mythemeshop

... existing entries (do not modify it)

What is a 302 redirect?

A 302 status code is commonly referred to as “temporarily moved.” This redirect doesn’t carry or pass the link value to the new URL. What it does do is redirect your site visitors into another web page temporarily.

STEP 4: modify robot.txt file

In this step you will need to prevent Google from indexing your cloaked URLs. To do this we will need to modify the robot.txt file.

If you are using Yoast SEO plugin in your site, then go to SEO >> Tools and select File editor. Here you can modify the robot.txt file. Add the following line in robot.txt file.

User-agent: *
Disallow: /go/

Now let's move on to the FINAL step.

STEP 5: Add Cloaked URL

In the final step you will need to replace your affiliate URLs with the newly created cloaked URLs. 

Find all the affiliate URLs in your blog posts and replaced it with cloaked URLs one by one.

Should I nofollow affiliate links?

Yes, absolultely.

If you are not adding nofollow to your affiliate links then you are doing a big mistake by leaking link juice to the affiliate product you are promoting.

Thus, you must also add rel=”nofollow” to prevent leaking PageRank to the affiliate advertiser.

It will take time if you have many blog posts but once done it will worth your time.

This manual process of cloaking affiliate link is very robust and fast unlike WordPress plugins which does the similar work but may slow down your website.

This is an awesome method to cloak affiliate links.

Click to Tweet

Some affiliate program also provide option to cloak the affiliate link. You can cloak the link from the affiliate website itself.

For example, A2hosting affiliate program has such features.

If you are promoting affiliate products of A2hosting or are planning to join its affiliate program then you can use its AffLinkProtector option to cloak your affiliate link.

After login to A2hosting, under Advanced Ad Tools select AffLinkProtector.

Now, enter the affiliate URL you want to protect under URL to protect / cloak and select HTML under Redirection type. Now select Generate.

On selecting Generate, a web page will download. Save this web page to your computer.

Now upload it to your own website.

Now, instead of using your normal affiliate code, you can reference your uploaded affiliate web page, and no one can strip off your affiliate ID.

See the image below.



If you have not yet joined A2hosting affiliate program, join by visiting this link.

Join A2 Hosting affiliate program


So, at the end of this article I am confident that now you know answer to the following questions-

  1. What is affiliate link cloaking?
  2. Why should you cloak affiliate links? 
  3. How to cloak affiliate links for free without any plugin in a WordPress site?

If you have any question or suggestion please comment below.

Sharing is Caring! If you liked this article please share it now.

Photo of author

Deepak Choudhary

Deepak Choudhary is the founder of He is a Blogger and an Affiliate Marketing Expert. He publishes useful articles for newbie bloggers related to the following topics - Affiliate Marketing, Email Marketing, Software Reviews, Blogging, WordPress, SEO, Passive Income, and more.

2 thoughts on “How to Cloak Affiliate Links Without Plugin in a WordPress Site?”

Comments are closed.