Skip to content


URL Masking (cloaking)

So you may have come across the term of cloaking URLs, this usually sounds evil and bad, like cloaked pages, which is something entirely different. Cloaking pages is presenting pages based on certain conditions, usually presenting a specific page to Google, for example. Doing this will get you banned and removed from Google’s index. Not good. Cloaking URLs is a slightly different concept. It’s showing a URL that usually points to something in your own domain. Once you click on the link you’ll be redirected to the ‘real’ destination URL.

For example a CJ link for eBay would look like this:
http://rover.ebay.com/rover/1/711-1751-2978-328/1?aid=10366506&pid=123456

But to cloak it you would make it look like this:
http://www.money-code.com/ebay

For this example we’ll use Apache’s module called mod_rewrite. Almost all installs of Apache have this installed, but some may not, so you’ll need to verify this. Also, this will need to be managed via a .htaccess file. This is another option that might not be available for you. Sometimes, some hosts will not give you the ability to manage mod_rewrite directives within .htaccess, so you’ll need to check here as well.

Simply create a file called .htaccess in the root of your site. Next we need to add our rewrite rule and action. Rewrite uses regular expressions, so you can get pretty tricky if you want, this example will be as simple as it can get.

RewriteEngine on
RewriteRule ebay$ http://www.ebay.com [QSA,L]
 

Basically, we’re turned on the ‘engine’. Our rule is ebay$ which means after the site name (www.money-code.com/) it’ll look for ebay and has to end at ebay. Meaning if we did this:
http://www.money-code.com/ebay/ it won’t work… only http://www.money-code.com/ebay

Another directive you may need depending on your set up is RewriteBase, this primarily is used if you have your applicaiton in a subdirectory to start with, etc.

If you’re not familiar with regular expressions, you should stop now and buy this book (Mastering Regular Expressions). RegEx will come in handy in the future! I basically can’t go a day without using some form of RegEx.

The second part of the line is a redirect destination. There are some flags at the end [QSA,L] which is [Q]uery [S]tring [A]ppend, [L]ast. We want to append any querystring data, and we want to close with this being the last rule.

Now, we’re not done. We need to do a few other things. Our anchor link will need the following attribute

rel="nofollow"
 

This tells the robots that items at the end of this destination is not relevant to the site and to not follow. Unfortunately, spiders will still follow this, but we have one more simple technique. We drop a robots.txt file in the root and add the following:

User-agent: *
Disallow: /ebay
 

Now, ‘good’ robots will pay attention to that and not follow the link.

Another option is to use PHP. You could create a link to point to the following:
http://www.money-code.com/ebay.php

ebay.php would contain the following code:

<?php
header("Location:http://rover.ebay.com/rover/1/711-1751-2978-328/1?aid=10366506&pid=123456");
exit();
?>
 

This accomplishes the same thing, but at the code level vs. server directive.

[Post to Twitter] Tweet This Post 

Posted in Affiliate Marketing, Programming. Tagged with , , .

10 Responses

Stay in touch with the conversation, subscribe to the RSS feed for comments on this post.

  1. Thanks for laying this trick out step by step. I thought of using the .htaccess that way, but guess I just needed to see it spelled out.

    What are your thoughts about server directive vs. code?

    It seems like the PHP option, if sent to a common directory like /reviews/ or /recommends/ or something less spammy sounding, would help you sort and organize easier than one long .htaccess file.

    Thanks for the robot/spider tricks as well, this is the best I’ve seen it laid out, nice and simple.

  2. admin said

    Great point. I’ve been going around this myself. I think in the end the .htaccess is the simpler solution.

    For example, if I’m following you correctly, you’re suggesting creating a directory called /recommends and in that directory you’d have php files (ebay.php, amazon.php, etc) or you could create a single php file (index.php) and pass a variable (ie: index.php?a=ebay) and handle the redirection.

    I think the first option would actually take more work. You’d have to create a new file for every new affiliate link vs adding a single line to .htaccess. The second option is a wash compared to the .htaccess, since you’d have to add a new header() call in the single switch/case file based off of querystring anyway. I feel that is the same as creating a new entry in the .htaccess.

    I have several sites that use both methods (not at the same time) just to see what I like best. I think I like the .htaccess the most. Also, I’m starting to see other sites, and how they work it (I’m only guessing). For example, I see johnchow.com use the directory strategy a lot (which I’m assuming is the .htaccess method).

    It might come down to what you’re more comfortable with.

    I’m glad this post was useful to you. Check back again, I’ll be adding a post on image URL cloaking for eBay images.

    hanji

  3. Hey there…suppose I used the PHP version, would this be tracked automatically say in my wordpress stats? How can I implement tracking so I can see how many click throughs I’m getting?

    I suppose I could try it and find out!

  4. admin said

    If you went with the PHP version, you’d be seeing traffic to ebay.php. I’m not too familiar with WordPress, so not sure what to say about wordpress stats, but you could put some analytics code on ebay.php. That may slow things down a bit, so might not be the best route, but your hosting site should show the ebay.php requests, etc.

    Hope this helps.
    hanji

  5. claudio said

    i really dont understand, if i have a page with an ebay rss on it, so lets say i have 50 auctions in rss on my website page all the links are rover.ebay if you mouseover them, how would i get to take off that rover so i and google see “mysite.com/whatever.php

  6. admin said

    Hello. Thanks for commenting. I don’t really want to just ‘give’ you the answer to your question.. but it’s really quite simple. You need to have something in common with all the rover code.. and something that you can ‘pass’ to a redirect page. From there, you should be able to re-assemble the rover code. I have quite a few stores using eBay.. and they all use this technique. You don’t have to change things by hand when using PHP.

    hanji

  7. I think I will use the PHP method for my affiliate redirect needs.

    my question for you hanji is?
    how would you code multiple links using the PHP page

    just list how the php page would view with 3 links on that php page

  8. admin said

    Hello

    If you wanted to use one script to handle multiple ‘targets’, then you would use a switch/case and pass a variable in the querystring. Name this file target.php


    < ?
    if(isset($_GET['go']) && strlen(trim($_GET['go'])) > 0){ // always check for existance of a variable first
    switch(strtolower(trim($_GET['go']))){
    case 'ebay':
    $url = 'http://rover.ebay.com/rover/1/711-1751-2978-328/1?aid=10366506&pid=123';
    break;
    case 'amazon':
    $url = 'http://www.amazon.com';
    break;
    default: // default if a 'bad' go value is passed
    $url = 'http://www.money-code.com';
    break;
    }
    if(isset($url)){
    header("Location:".$url);
    exit();
    }
    }else{
    header("Location:http://www.money-code.com"); // no go variable found, redirect them back to the main page
    exit();
    }
    ?>

    Then to create a link do the following


    Sign up to ebay

    Hope this helps!

    hanji

  9. In a sea of worthless affiliate marketing blogs, this one is definitely in the top five.

    Thanks so much, can’t wait to read more.

  10. admin said

    Thanks Tyler! Love to hear any ideas you have.. or questions.

    Thanks!
    hanji

Some HTML is OK

(required)

(required, but never shared)

or, reply to this post via trackback.

Powered by WP Hashcash


Tweet This Post links powered by Tweet This v1.3.9, a WordPress plugin for Twitter.