Knowledge.ToString()

How to Enable Canonical Url for SEO in DotNetNuke 5.x?

Recently DotNetNuke 5.x has changed much of Url rewriting. I had updated my website running on DotNetNuke 4.9 to 5.x and now I have lost all my Google rank which were depending on old URLs.  Now all new URL seems very search engine friendly but I need my Google rank back to the new URL but is not possible because I have to create duplicate pages with new permanent redirect. Of course, there is another way of getting it back and even for future, we can save our google rank using Canonical URL.  Now we will learn what is canonical url and how we can add it in existing DotNetNuke installation.

What is Canonical Url?

DotNetNuke pages can be accessed by different urls. For example, the home page can be accessed by

  • https://www.vishalon.net/Default.aspx
  • https://www.vishalon.net/Home/tabid/53/Default.aspx
  • https://www.vishalon.net/tabid/53/Default.aspx

All these URL will land us on the same page. All search engine will “think” it is a duplicate content and sometime it may “penalize” the site ranking.  To reduce duplicate content all search giants reached to an agreement to honor a special link in HTML which will refer the page with a single URL (you may call a permanent new url). This link is called Canonical URL. Even though the actual URL that user typed to get the content may vary but the canonical URL will be same and will be considered by search engine as a URL using which it will count all ranking. Here is a sample <link> tag in <head> tag.

<link rel="canonical" href="https://www.vishalon.net/Home.aspx" />

For all 3 previous URL, it will be considered as the duplicate URL of canonical URL and all the page rank, indexing will be based on canonical URL.

How to add Canonical URL to DotNetNuke?

It is very simple to add Canonical URL to your DotNetNuke installation. It requires to add a line into /Default.aspx.vb file in InitializePage() function right before the statement shown below

Page.Header.Controls.Add(New LiteralControl("<link rel=""canonical"" href=""" & objTab.FullUrl & """ />"))
If NonProductionVersion() AndAlso Host.DisplayBetaNotice Then
...
End If

Now your DotNetNuke pages have canonical URL.

Google Analytics for Canonical URL in DotNetNuke

New URL in DotNetNuke is smart enough to confuse your Google Analytics and same page with slightly different URL will be recorded separately. Now if you want to aggregate data based on Canonical URL, you have to make a change in Google Analytics code. If you are using built in Google Analytics code that now ships with DotNetNuke as one of the desktop module, you have to make following changes in the /SiteAnalytics.config file. If you are using your own code, you have make changes where you have manually added code.

var pageTracker = _gat._getTracker([TRACKING_ID]);
var canurl = “”;
try {
    var links = document.getElementsByTagName(‘link’);
    var link = “”;
    for (var i = 0; i < links.length; i++) {
        link = links[i];
        if (link.getAttribute('rel') == "canonical") {
            canurl = link.getAttribute('href').replace(/^https?:\/\/[^\/]*\//i, "/");
            break;
        }
    }
} catch (e) {}
pageTracker._trackPageview(canurl);

Share

Comments

2 responses to “How to Enable Canonical Url for SEO in DotNetNuke 5.x?”

  1. Vishal Avatar
    Vishal

    @Matt
    Last bit of code is not required but if you don’t want Google Analytics to report 3 different URL for the same page, you should put that code. If you have GA code in default.aspx, then last bit of code should also be placed in default.aspx and should be removed from “/SiteAnalytics.config” file otherwise, GA will report two visits instead of one. You should have GA code only once within the page.

  2. Matt Avatar
    Matt

    Nice work. Question – I usually just keep the ga code in the default.aspx – would that last bit of code still work? Guess I could try, but don’t want to drop anything if you already know 🙂

Leave a Reply

Your email address will not be published. Required fields are marked *