Please can someone advise on how to set the canonical for each individual product. The some products on my website currently have 3 URLs:
www.mydomain/bluewidget
www.mydomain/mens/bluewidget
www.mydomain/ladies/bluewidet
I'd like to be able to set the canonical to the first URL above.
I can set the homepage canonical with the code:
Code: Select all
<?php $host = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
if($host == 'www.mydomain.co.uk/')
{ ?>
<link href="https://www.mydomain.co.uk/" rel="canonical" />
<?php } ?>