There are many advertisers on CJ’s webservices that have a product catalog that use links that can easily be cleaned up on your site using mod rewrite commands. A simple str_replace function and updating the .htaccess file on your server will do the trick. It doesn’t matter if you are using SOAP or REST api calls, you can easily rewrite the urls as outlined in this article.
I am going to base the content off of the same code that I am running on one of my sites. If anybody reading this article is a boater’s world affiliate, the code is here for you to grab, by the way. I am only showing one of the links. You will need to rewrite the url’s going from each domain that cj uses for tracking purposes. Also, it is detrimental to insure that the click-123456-12345678 is indeed correct. The first number is your PID that you have to enter into the API code to make the call so if you get that number wrong, you definitely need to double check it. The second number in the series is the creative, I think, but am not clear on.
We are using the boaters world connection because of it’s simple urls. The urls appear like this: http://boatersworld.com/product/12345.htm&cjsku=12345. If you notice the product number and cjsku is the same number.
- Run the script on your site to get an idea of how the links look. You should copy the link to text editor where you will later update this to the .htaccess file.
- View source code to copy the url in html. You will need this to update your webservices API call to present a friendly link to your site’s visitor. The .htaccess will redirect the link to the advertisers page and you still get commission or referral fees for any sales or leads generated.
- Open the .htaccess file. At the bottom of the RewriteRules and before the RewriteBase statement, add the following command: RewriteRule ^product/([a-zA-Z 0-9?-]+)-([a-zA-Z 0-9?-]+) http://jdoqocy.com/click-123456-12345678?url=http://www.boatersworld.com/product/$1.htm&cjsku=$1.
- In the php code where you make your API call it is important to copy the url exactly from the source code from your browser. The code uses the utf-8 code for symbols. i.e. <space> is notated %20. After you make your API call in the php code, your code should look like this [SOAP REFERENCE]:
$click_url = $result['searchReturn']['products']['products'][$i]['clickUrl'];
This is for the actual url to the product. Now below all the calls, you should add these lines:
$click_url = str_replace("%2F","/",$click_url);
$click_url = str_replace("%3A",":",$click_url);
These commands will convert the UTF-8 to the actual symbols used in the url. (:/) Now for the line of code that I have in my .htaccess file, I will use that to rewrite the urls on my site like this.
$click_url = str_replace("http://www.tkqlhce.com/click-123456-12345678?","http://alabamatombigbeefishing.info/product",$click_url);
This will change the url to show my domain instead of the tracking domain. Now to complete the cleaning of the urls so that the url looks like this: http://alabamatombigbeefishing.info/product/MP84149749-Catfish_Master_Combo_8_Medium.html, we will add the following code:
function seo_str($string)
{
$string = html_entity_decode($string, ENT_QUOTES);
$string = ereg_replace("[^a-zA-Z0-9 ]", "", $string);
$string = ereg_replace(" +", " ", $string);
$string = str_replace(" ", "_", $string);
return $string;
}
$click_url = str_replace("url=http://www.boatersworld.com/product","",$click_url);
$click_url = str_replace(".htm","",$click_url);
$click_url = str_replace("cjsku","",$click_url);
$click_url = str_replace("&=","",$click_url);
$name1 = seo_str($name);
$click_url2 = 'http://alabamatombigbeefishing.info/product/'.$sku.'-'.$name1.'.html';
<a href=$click_url2>$name</a>
You can preview the code in action at the bottom of this page: Mississippi State Record Flathead caught on Tombigbee. Note that we wrote a custom function named seo_str at the very beginning of this code. This function allows us to make an SEO friendly url that .htaccess and the search engines, by the way, will love.You have now gotten rid of the ugly urls and have made urls that look like they belong to your site. You should notice an increase in clicks now, as well. A lot of visitors won’t click through if the url in the status bar doesn’t look friendly. My click rate increased 5 times within 2 months of implementing this on my various sites.
If you aren’t using the CJ API but are interested in it and haven’t found a plugin for wordpress that looks natural to your site, check out the cjAffShop plugin that I have written. It works seamlessly with wordpress allowing you to add as many advertisers, keywords, and returns as you wish. Before our wedding, my wife showed off a dress that she was interested in on her blog. She wound up not buying that style dress but really liked it. You would never know that she didn’t just put the picture and link on her site to show it off, looking at it. Preview for yourself at PolkaSpotFarm.
You can get this plugin now, for a limited time, for only $27. I have both the SOAP and REST versions available, though, if your server can handle the REST call, I recommend. CJ is slowly phasing out the SOAP API calls.
