Cloak Affiliate links with BunnyCDN

This tutorial will show you how to cloak your affiliate links using BunnyCDN. By cloaking your links, you can hide the original destination of the link, making it harder for users to block or remove your affiliate tracking code. This will help to increase your earnings and improve the aesthetics of your website. 😍

Advantages of doing link cloaking

  • It helps in turning long affiliate URL to short, sweet and memorable.
  • It helps in managing all affiliate programs links at one place.
  • It helps in tracking click efficiently.
  • It looks more professional, branded than sharing 3rd-party domain.
  • It improves e-mail delivery.
  • It is easier to nofollow all links.
  • It is also possible to do geo-redirection with cloaking.
  • It helps in maintaining a kind of transparency with visitors.

Why use BunnyCDN for Link Cloaking?

A plugin like Affiliate Link Lite works only works with traditional WordPress running over PHP and MySQL server.

  • In case you are running a Serverless site, Static WordPress or HTML site or maybe using the old-fashioned Google Blogspot platform, you can let BunnyCDN professionally handle all your redirection.
  • Easy to track logs.
  • Off-load ‘Affiliate’ links to BunnyCDN server to avoid Single Point of Failure. Your link will continue to work even if your main site goes down.

There are two ways to set up redirection or link cloacking in BunnyCDN.

  1. Using the Edge Rule feature in a Pullzone
  2. Using Cloud Storage zone and linked Pull zone

Method 1. Using the Edge Rule

BunnyCDN offers a powerful edge rule feature called “Redirect to URL“. We can use it to set up redirection based on conditional path, country, etc.

redirect feature introduction
  • For example, when the user will visit https://affiliate.gulshankumar.net/some-brand/
  • They will go to your defined affiliate link for that particular brand.

Let’s see how it can be done.

Step 1. Add a Standard Tier new Pullzone

  • Enter unique pull zone name, for example affiliate-partner 
  • Set Origin URL to https://www.example.com/404
adding a new pull zone

Step 2. Select all Pricing Zones for the fastest redirection

pricing

Step 3. Skip the instructions about setup, we are going to do it differently.

skip part

Step 4. Add a subdomain as custom hostname in Pull zone

  • For example, affiliate.gulshankumar.net

Step 5. Point subdomain using CNAME record to the Pullzone hostname

  • If you’re already using nameservers of BunnyCDN, it automatically has done.
  • If you’re using Cloudflare managed DNS, then create there A CNAME and keep proxy turned off.
point CNAME record

Step 6. Install SSL Certificate and force HTTPS

pull zone host setup

Step 7. Add a new Edge Rule

Edge Rules allow you to fine-tune how your pull zone behaves based on the request path as well as set up some more advanced routing and features. To get started, you can have a look at our Edge Rule Knowledge Base where we provide useful articles to help you set things up.

BunnyCDN
  • Action: Redirect to URL
  • Description: Enter a memorable name for edge rule. Example: BunnyCDN Affiliate link
  • Redirect URL: Enter the affiliate link https://bunny.net/?ref=example
  • Condition Matching: Match Any
  • IF Conditions: Request URL (Match Any)
  • Trigger path: */bunnycdn*
  • Save Edge Rule
sample redirect edge rule

Repeat this process for creating cloaked link for all affiliated brand.

Keep in mind, in one pull-zone you can have maximum 20 edge rules. If you have more than twenty links, I strongly recommend using the Storage option as described below.

Method #2. Using Cloud Storage Zone

BunnyCDN offers inexpensive cloud Storage services that we can use to host HTML pages for creating cloaking affiliate links. We can do redirection using JavaScript and meta-refresh as the fallback.

Step 1. Login to BunnyCDN Dashboard, add a new Storage zone.

add bunnycdn storage zone

Step 2. Complete Basic Details

  • Name: Enter any unique name, for example gulshan-aff
  • Main Storage Region: Europe (Choose any nearest from you)
  • Enable GEO Replication in all regions (Optional step for faster redirection)
  • Click on + Add storage zone button
gulshan aff

Step 3. Connect your Storage to a new Pull zone

connect pullzone

Step 4. Enter new Pull zone information

  • Namegulshan-aff (It can be different than storage name)
  • Choose Standard Tier (It allows serving data from all PoPs)
  • Select all pricing zones for the better experience
  • Then, click on +1 Add Pull Zone
connect pullzone 1

Step 5. Skip instructions

skip instructions

Step 6. Add custom hostname for Pull Zone of Storage Zone gulshan-aff

add custom hostname

Step 7. Point DNS record to your Pull Zone hostname

For example

Record typeNameValue
CNAMEaffiliategulshan-aff.b-cdn.net

If you use Cloudflare DNS, keep Gray cloud to have DNS only mode.

If you’re using BunnyCDN DNS, no additional action is required.

Step 8. Enable Free SSL and Force SSL (HTTPS) in one click

installing free ssl in bunnycdn pull zone

Step 9. Add x-robots: noindex, nofollow header for all Affiliate links

  • Action: Set Response Header
  • Description: SEO-Friendly Affiliate links
  • Header namex-robots
  • Header valuenoindex, nofollow
x robots setup
  • Condition Matching: Match Any
condition matching
  • This rule will apply x-robots: nofollow, noindex header for all affiliate links.
condition rule

Step 10. Go back to Storage which you created in last step six.

Now let say the Brand name is BunnyCDN and your affiliate link is https://www.bunny.net/?ref=example

So we need redirection from our custom hostname to affiliate path.

  • From https://affiliate.gulshankumar.net/bunnycdn
  • To https://www.bunny.net/?ref=example

Steps to achieve it

  • Add a new directory with the brand name, for example bunnycdn which will slug for its referral link.
adding a brand name directory

(always prefer naming in the small letter, all storage object name is case-sensitive)

  • Next, add an index.html file for redirection with meta refresh and JavaScript. Make sure to modify link as per your use case.
<!DOCTYPE HTML>
<html lang="en-US">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="refresh" content="0; url=https://bunny.net/?ref=example">
        <script type="text/javascript">
            window.location.href = "https://bunny.net/?ref=example"
        </script>
        <title>Page redirection</title>
    </head>
    <body>
        If you are not redirected automatically, follow this <a href='https://bunny.net/?ref=example'>link</a>.
    </body>
</html>
index file
  • The URL will be accessible over https://affiliate.gulshankumar.net/bunnycdn
  • or with slash https://affiliate.gulshankumar.net/bunnycdn/
  • It will redirect to the target brand affiliate path.

Important Informations

Step 11. Avoid caching redirect response in the in browser

do no cache in browser 1

How to create bulk redirection?

If you want to setup 100 affiliate links, create 100 folders and its index.html file at your PC and upload using your favourite FTP application. That’s the fastest way.

I recommend you do the first few tests before final deployment. Once deployment finishes, always keep backup of all folders to make changes in future easily by re-uploading.

How to avoid Browser Cache and still maintain Edge cache?

Go to Pull Zone, General, Browser Cache Expiration Time, set the Browser Cache expiration time to Override: Do not cache. Or, you can set min 30 seconds. That should also work great. Remember, for changeable link like this it is better to keep the lowest TTL for browser.

What is technical difference in setting up redirection via Edge Rule and Storage?

The edge rule method is quick and easy for 301 redirections, limited to 20 edge rules per Pull Zone. The edge rule method is slightly faster.
The Cloud Storage method allows you to serve unlimited HTTP 302 redirections with greater control over HTML coding.

When to purge Cache?

You can update your affiliate link anytime in future, so purging cache is required. Regardless of both method, if you make any changes in Storage or Pull Zone make sure to purge the cache.

How to test either my Redirection is working or not

Open terminal or CMD and type curl -I https://example.com/brand/ this will help in checking HTTP Status code and overall response. You can also use the Chrome Developer tool for analysis.

Can I use Perma Cache with Storage method?

Yes. It can help in redirecting faster when uncached.

Leave a Comment

2 thoughts on “Cloak Affiliate links with BunnyCDN”

  1. thanks for this writeup. one question:

    you are writing: “in one pull-zone you can have maximum 20 edge rules”

    this does not seem to be the case (i’m still in my trial period).

    a also can’t seem to find any information regarding this in documentaiton by bunny.

    i have found this article: https://bunny.net/blog/introducing-edge-rules-v2/
    there this is stated: “we are currently considering charging a small monthly fee of around $1 for each rule after a certain number of free rules for each zone”

    however i also cannot find any documentation, if this is indeed the case.

    Reply