Canonical tag for cms and other custom url in magento

Topics focus on Web Developments, Programming, Database, Digital Marketing Tutorials, Code Snippets, SEO, Social Media Marketing and Inspirational articles.

Canonical tag for cms and other custom url in magento

Canonical tag for cms and other custom url in magento

Here, We will explain How to canonical tag for cms and other custom url in magento. It will helps you in Search engine optimization of magento store.

The code for remove trailing slash and put canonical url for cms and other custom url in magento for Search Engine Optimization purpose:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
 <?php
    if ($_SERVER["HTTPS"] == "on") {
        $type .= "https://";
    }else{
        $type .= "http://";
    }
    $finalUrl = "$type$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";
    if(substr($finalUrl, -1) == '/') {
        $finalUrl = substr($finalUrl, 0, -1);
    }
    $uri = $_SERVER[REQUEST_URI];
    if(substr($uri, -1) == '/') {
        $uri = substr($uri, 0, -1);
    }
 
    if($uri == '/index.php'):
?>
        <link rel="canonical" href="<?php echo $type.$_SERVER['HTTP_HOST']; ?>" />
<?php        
    elseif($uri == '/contacts' || $uri == '/news' || $uri == '/retailers' || Mage::app()->getFrontController()->getRequest()->getRouteName() == 'cms') : 
?>
        <link rel="canonical" href="<?php echo $finalUrl; ?>" />
<?php 
    endif; 
?>

Add comment


 

Pin It on Pinterest

Share This