Earthtracker's Blog

Just another weblog

Magento Canonical URL problem from outside of main category solve

In magento , if you add a product in categories multiple categories, and like to display product from outside of the categories, it will no reflect the correct url, it will create a url with the domain name + product url title,It will cause duplicate contents in google, to resolve the problem, here is the solution,My special thanks to



   if($_categories[0]==2) // here 2 is root category id




   $_categories = $_product->getCategoryIds();

   $_category = Mage::getModel('catalog/category')->load($_categories[$cat_count]); 

   $caturl=explode('.html', $_category->getUrlPath());      
   $product_url = Mage::getUrl($caturl[0]).basename($_product->getProductUrl()); 

Leave a comment »