How can I make a dynamic canonical tag on Magento?

We generally recommend to hide internal site search from getting indexed

/app/design/frontend/{your_package}/{your_theme}/template/page/html/head.phtml

Add this code:

<?php
// code for show canonical tag on all page
$current_url = Mage::helper('core/url')->getCurrentUrl();
if(!empty($current_url))
{
$url2 = substr($current_url, 0, strpos($current_url, '?'));
if(!empty($url2)) {
?>
<link rel="canonical" href="<?php echo $url2; ?>" />
<?php } else { ?>
<link rel="canonical" href="<?php echo $current_url; ?>" />
<?php } } ?>

Aly Chiman

Aly Chiman is a Blogger & Reporter at AlyChiTech.com which covers a wide variety of topics from local news from digital world fashion and beauty . AlyChiTech covers the top notch content from the around the world covering a wide variety of topics. Aly is currently studying BS Mass Communication at University.