Joomla CMS Canonical SEO Tag Hack

From time to time you might have a duplicate homepage within Joomla, possibly from a poor setup! Whatever the reason the code below will help avoid a duplicate content penalty from Google. Go to the <head> section of your theme and paste the below code. Take a backup of any theme files before modifying.

<?php

$host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'www.domainname.co.uk/duplicate-page.php') 
{
     echo '<link rel="canonical" href="http://www.domainname.co.uk/"/>'; // echos canonical link
}
elseif($host == 'www.domainame.co.uk/') 
{
    echo '<link rel="canonical" href="http://www.domainname.co.uk/"/>'; // echos canonical link
}
?>