Rewriting your ECU URLs with PHP

by Jason on February 8, 2010

This has been taken from the blog over at Insight-UK, where the affiliate manager Bob (who has now moved to Webgains) came up with the method for you to rewrite your URLs, here it is straight from the post:

There are currently 2 methods to embed the Content Units into your website. JavaScript, or PHP. The JavaScript method is the easiest but is not the best as Search Engines cannot index JavaScript. If you have the technical skills, you can drop the PHP code that ECU supply directly into your website. This allows search engines to know what products you are offering. However, there is still the downside that for every product you promote you have an external link to This is generally bad SEO practice as every external link is a drop in page rank. Thankfully, ECU provide the code in the anchor tags, so you shouldn’t be penalised too much, if at all. In addition, most PHP servers have a security setting which prevent this code from running.

There is the fact that some folks just prefer to see that the links are on their own website, rather than an external website. For this reason, I’ve come up with a different bit of PHP code. If you use the PHP code supplied by ECU; then I’d highly recommend you implement this code. For an example of both php methods go here:

The code is as follows and goes wherever you want the content unit.

    Retrieve HTML for product unit.
    Note: 'fopen wrappers' must be enabled. Requires PHP 4.3.0. or above.
    Code by Bob DeVeaux for ECU
    This re-writes the ECU link to the same domain as the code

// function for downloading file
function curl_get_file_contents($URL)
    $c = curl_init();
    curl_setopt($c, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($c, CURLOPT_URL, $URL);
    curl_setopt($c, CURLOPT_CONNECTTIMEOUT, 5000);
    curl_setopt($c, CURLOPT_TIMEOUT, 10000);
    $contents = curl_exec($c);

    if ($contents)
        return $contents;
        return false;

$ecu_mid = 839; // your member id
$ecu_uid = 20212; // your unit id
$ecu_tracking = ''; // optional tracking id
$ecu_keywords = ''; // optional keywords for random product unit
$ecu_debug_mode = 'no'; // debug mode (yes or no)
$domain = "http://".$_SERVER["HTTP_HOST"];
$path = '/blog';
$ecu_url =

// cURL download file.
if($content = curl_get_file_contents($ecu_url))
    $content = str_replace('href="',
                            'href="'.$domain.$path, $content);
    print $content;

You then need your own version of product.php in the location you specified for ‘path’.

$domain = "http://".$_SERVER["HTTP_HOST"];
$qs = explode('product.php', $_SERVER['REQUEST_URI']);
$url = ''.$qs[1];
header('HTTP/1.1 301 Moved Permanently');
header("Location: ".$url);

The final step is to prevent search engines from spidering the redirect page by editing your robots.txt.

Disallow: /PATH_HERE/product.php

Amazon Users
If you have products from Amazon in your units, you will also need to add the following page:

amazon_product.php in the location you specified for ‘path’.

$domain = "http://".$_SERVER["HTTP_HOST"];
$qs = explode('amazon_product.php', $_SERVER['REQUEST_URI']);
$url = ''.$qs[1];
header('HTTP/1.1 301 Moved Permanently');
header("Location: ".$url);

Plus the robots file will need amending to:

Disallow: /PATH_HERE/product.php
Disallow: /PATH_HERE/amazon_product.php

I’d like to thank Bob DeVeaux for coming up with this solution for us. If you would like to include any Insight products in units, or indeed use their Weekly Deals managed unit, that would help thank them for this useful code.


Matt February 10, 2010 at 1:32 pm

Thanks for this, I just tried it out and it looks cool.

I noticed that amazon feeds use amazon_product.php instead of product.php will this effect things or will it still work OK?

Jason February 10, 2010 at 3:03 pm

Hi Matt

Well spotted, yes, you will need a separate php page for the amazon products, I will update the article for you above

Carl February 10, 2010 at 3:13 pm

Going to give this a go tonight! watch me make a mess of my site! 🙂

Bob DeVeaux February 28, 2010 at 10:54 pm

Glad you folks like it 🙂

Sam March 4, 2010 at 3:03 pm

I’m giving this a go today, fingers crossed!

Zac Zheng May 15, 2010 at 5:08 pm


Thanks Bob DeVeaux and ECU!

Comments on this entry are closed.

{ 1 trackback }

Previous post:

Next post: