Sometime back I wrote post about Canonical Urls. Indeed Canonical URLs is one of the important chapter of SEO and a way to avoid getting page rank getting distributed among different Url formats with same targets.
Along with Canoncial Urls I also wrote about implementing them in Umbraco site. In that post I used XSLT approach of Umbraco to generate Canoncial url for the pages. Recently Umbraco team released new version 4.6.1 for Umbraco CMS engine and one of the great feature they added was the support for Razor syntax. Yes, Umbraco now supports Razor syntax. And for those guys, including me, who dislike XSLTs, this is a great alternate for them. Now we can write the logic in C# rather then in XSLT. Thanks Umbraco Team!!!.
Here is a piece of code for generating canonical url for Umbraco based site using Razor syntax.
@using umbraco@using System@{ var cononicalUrl= String.Empty; }@if(umbraco.library.RequestServerVariables("HTTP_HOST").ToLower().StartsWith("www"))cononicalUrl = string.Concat("http://", umbraco.library.RequestServerVariables("HTTP_HOST"), Model.Url);elsecononicalUrl = string.Concat("http://www.", umbraco.library.RequestServerVariables("HTTP_HOST"), Model.Url);<link rel="canonical" href="@cononicalUrl" />
See how easy and simple it looks compared to XSLT one at {Link}
I admire the valuable information you offer in your articles. I will bookmark your blog and have my children check up here often. I am quite sure they will learn lots of new stuff here than anybody else!.
ReplyDelete