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.
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
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:
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:
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.
Related posts:
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.
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
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!
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
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
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
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
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
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.
Thanks Tyler! Love to hear any ideas you have.. or questions.
Thanks!
hanji
why don’t you just use the http://www.tinyurl.com
Hello pedro
The issue with url masking (also known lately as SEO redirects) is that Google will penalize you if you have too many external pointing links. So using tinyurl.com would be a link outside of the domain. By doing the mask, all the links appear to be going internally.
Second reason not to use tinyurl or other 3rd party URL shortening service, is that it’s now against EPN TOS to do this. Thanks for commenting!
hanji
admin´s last blog ..0 Followers on Twitter is being addressed
Hey, i have a redirect setup right now like this:
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.* [NC]
RewriteCond %{HTTP_HOST} ^([^.]+)\.domain\.com
RewriteCond /home/sites/domain.com/public_html/users/%1 -d
RewriteRule ^(.*) http://domain.com/users/%1/$1 [L]
so if i type milch.domain.com, and the folder /users/milch exists, it changes the URL to domain.com/users/milch. So my question is, how can I make it still appear as the subdomain milch.domain.com while using the /users/milch folder and the index file in it?
Hello milch
Are all the folders in /users owned by the same owner? If so, you can do a file_exists() or is_dir() using PHP as your condition. I might be misunderstanding your question. Is the index file going to be in milch.domain.com.. and you need to redirect to domain.com/users with a value?
If this is correct I would create my script similar to this (not tested and I’m just coding from the hip here):
< ?
$domain = $_SERVER['SERVER_NAME'];
$subdomain = explode('.',$domain);
if(is_array($subdomain) && sizeof($subdomain) == 2 && (isset($subdomain[0]) && $subdomain[0] != 'www')){
$user = $subdomain[0];
unset($subdomain);
$path = '/home/sites/domain.com/public_html/users/'.$user;
if(file_exists($path) && is_dir($path)){
header("Location:http://domain.com/users/".$user);
eixt();
}else{
// directory doesn't exist.. do something
}
}else{
// invalid domain.. do something
}
?>
hanji
I am doing free hosting. a php script would not work because each user would have to have it, understand what it is and how to use it/not break it. I have to do it in a .htaccess file. let me be more specific. I want milch.domain.com to point to doamin.com/users/milch while still displaying milch.domain.com in the URL. the previous config i posted will redirect milch.domain.com to domain.com/users/milch and that is the new URL, so the subdomain was pointless.
Hmmm.. seems like you need to set server alias with handling in a vhost file. I don’t think you can do this via .htaccess level though. You would simply add the ServerAlias of milch.domain.com with the Directory directive pointing to the proper directory. Do you have access to server config? Or only .htaccess?
hanji
I only have access to the html docs folder, but none of the main apache configuration, hence my dilemma.
Hey! Quick question!
How would you code multiple links using the PHP page??
Bridgett Salle´s last blog ..Google Profit System