2 Ways to Cloak Affiliate Links

In the world of affiliate marketing, the word “cloak” gets thrown around a lot and means different things to different people.  So let’s be clear:

Link Cloaking

Definition: Using on page techniques to obfuscate the destination URL of a link when the user hovers over it.

Purpose: To hide ugly, complex, or affiliate code laden URLs from the user.  The idea is this: when the user hovers over a link, he will see the destination URL in the browser’s status bar.  A nice, clean URL, makes him feel warm and fuzzy inside and more likely to click through.

Referrer Cloaking

Defintion: Using off page techniques to hide or obfuscate the true referring page.

Purpose: To keep people out of your shit.  When you send traffic to an offer, the final destination is the merchant’s page.  If you don’t cloak the referrer, the merchant will be able to see exactly where the traffic is coming from.  This might be your landing page or, if you are direct linking, your traffic source.  “Tall fences make good neighbors”.

Referrer Cloaking is done via double-meta refresh and will not be the subject of this post.  However, it is worth noting, Prosper202 can handle this for you and you should definitely be doing it.  Instead, I’m going to be showing you how to cloak links.

How to Cloak Links

Option 1: PHP Redirect

Technically, this is not on page, but this is the most common method I see people using.  It works, looks pretty good and does not rely on javascript so it will work 100% of the time. The only downside is you do not have absolute control of how the link will look in the status bar.  Here is how to do it.

File: index.html

<a href="goto-yahoo.php">Visit yahoo.com</a>

File: goto-yahoo.php

header( 'Location: http://www.google.com/' ) ;

How it works: if the user hovers over the “Visit yahoo.com” link, he will see something like “yourdomain.com/goto-yahoo.php” in the browser status bar. You can name this php file anything you want, I just chose “goto-yahoo.php”. When the user clicks on the link, the “goto-yahoo.php” file uses a php redirect to send the user wherever you want him to go. I chose to send him to Google to illustrate a point: what the link says, and where it goes can be two different things. As you can see the limitation of this method is it must end with “.php”. But you can get fancier….

Option 2: Javascript Cloak and Redirect

File: index.html

<a href='http://google.com/' name='http://yahoo.com'>Visit yahoo.com</a>
<script language="javascript">
_links = document.getElementsByTagName("a");
for(i=0;i<_links.length;i++) {
    if(_links[i].name) {
        docloak = function() {
            _cloak = this.href;
            this.href = this.name;
            this.innerHTML = _cloak;
        _links[i].oncontextmenu = docloak;                 
        _links[i].onclick = function() {
            window.location = this.name;
            return false;
        _tmp = _links[i].href;
        _links[i].href = _links[i].name;
        _links[i].name = _tmp;

How it works: Make a link as usual. Add the “name=” attribute and set it to whatever you want displayed in the status bar. The javascript code at the bottom of the file does the rest. Make sure you put the javascript code AFTER all of the links on the page. When the user hovers over the link, he will see whatever you set in the name attribute. As you can see, this technique allows you to control exactly what gets displayed in the status bar. If javascript is disabled, the user will see the real destination url, but that’s about the only downside.

Leave a comment



CommentLuv badge


  • Notmah Reelname

    If you are using the php redirect method your link doesn’t _have_ to end in php. Using apache’s AddHandler config in httpd.conf or .htaccess you can execute any extension through php. For example, with

    AddHandler application/x-httpd-php .com

    your php file (and link) could be:



    • True that. Changing Apache config works great. But I was saving that tip for ctrgenius.com

  • Thanks for the great tips. Got here from the PPV playbook forum post that you made while helping.


  • I discoveried something new about PHP\Scripts progamming for myself.


  • That’s an excellent article. I found this while searching for “Datafeed link cloaking” on Google.

    I’m going nuts with finding a link cloaking script that can help me cloak thousands of links on the fly. The only reason I wish to cloak links (if that’s the correct term) is to make external links look like internal links.

    I wish to use links like this: mySite/out.php?id=Site2 and when the link is clicked, the Site2 link is executed and the visitor is redirected to Site2.

    Can anyone help me with a script that can accomplish this task?

    Appreciate any help you guys can provide.


    • Did you read this? http://ctrtard.com/affiliate-marketing/better-affiliate-link-cloaking-for-seo/ That post covers the ultimate way to link cloak. You can fairly easily use the techniques I described in that post and do link cloaking on the fly. I do that myself on my own data feed sites.

      If you need help implementing this quickly, I do custom programming. Hit me up using the contact form. Thanks for reading!

  • This works great, wordpress users can also use a plugin called WP no external links, works very similar except you end up with something link: youdomain.com/goto?=http://destination.(com)

  • When i right-click the link,the real-url is showing. How to fix?
    PageLines Discount’s latest blog post: PageLines Discount Code: Save on all PageLines

  • Thanks for JS cloaking. I have the same problem like the writer above… when i right-click the link, i see the url in name attribute and not the url in href. How to fix this, is there any solution?

  • Heya i’m for the primary time here. I came across this board and I to find It
    truly helpful & it helped me out a lot. I am hoping to give something
    back and help others like you aided me.


[…] Not to be confused with referrer cloaking, cloaking affiliate links is typically done to present a nice looking URL to the user. The idea is, the savvier visitor might see a weird URL in the browser status bar and be less likely to click—so it’s best to cloak the link. If you’re using this technique for a landing page that you’re driving paid traffic to, then one of the usual link cloaking methods is fine. […]

2 Ways to Cloak Affiliate Links [Link] « November 8, 2010


Related posts by category

Related posts by tag