IMPORTANT: This version of Sitefinity CMS is out of support and the respective product documentation is no longer maintained and can be outdated. Use the version selector to view a supported product version.
Canonical URLs are one of the crucial advancements in SEO practices. In many cases you may want to display the same content via one or more pages. This is called a duplicate content. However it's very difficult for a search engine to make a determination which value is correct if it comes the same or extremely similar piece of content with different URLs. Also search engines like Google have decided that they don't like duplicate content and pages with duplicate content don't rank well. For that purpose a canonical URL is used. It represents a tag that is part of the HTML header of a web page, in the same section where the title and meta description tags are rendered. Here's an example of a link tag:
<
link
rel
=
"canonical"
href
"http://canonical-url-goes-here"
/>
The Canonical URL tag attribute is similar in many ways to a 301 redirect from an SEO perspective. In essence, you're telling the engines that multiple pages should be considered as one (which a 301 does), without actually redirecting visitors to the new URL.
Sitefinity already provides a canonical URLs implementation for the following widgets:
* News
* Event
* Blog post
* Image gallery
* Video gallery
* Download list
* List items
* Products list
For more information, see Enabling and disabling Canonical URLs service.
Imagine that your pages are using content blocks to store content. Also you wish to keep versions of the content by adding new site and copying all the pages from the previous one. The problem here is that the same content will be accessed by different URLs - classical SEO problem. Here you will have to add a canonical URL for the pages choosing which is your default version. Follow the steps below to add canonical URLs to pages:
Open your SitefinityWebApp in Visual Studio and add new web user control.
Name the control CanonicalMetaTagSetter.ascx
protected
void
Page_Load(
object
sender, EventArgs e)
{
//if the url contains a virtual directory, the application virtual path will be replaced
//by the url of the current (default) site.
string
defaultSiteUrl = Telerik.Sitefinity.Multisite.MultisiteManager.GetManager().GetSites().FirstOrDefault(a => a.IsDefault).LiveUrl;
var liveUrl = SystemManager.CurrentContext.CurrentSite.LiveUrl;
var requestUrl = SystemManager.CurrentHttpContext.Request.Url.AbsoluteUri;
canonicalUrl = requestUrl;
if
(!liveUrl.Equals(defaultSiteUrl))
canonicalUrl = requestUrl.Replace(liveUrl, defaultSiteUrl);
}
this
.SetCanonicalMetaTag(canonicalUrl);
/// <summary>
/// Sets the canonical meta tag.
/// </summary>
/// <param name="href">The href.</param>
private
SetCanonicalMetaTag(
href)
HtmlLink canonicalLink =
new
HtmlLink();
canonicalLink.Attributes.Add(
"rel"
, CanonicalMetaTagSetter.CANONICAL);
"href"
, href);
.Page.Header.Controls.Add(canonicalLink);
const
CANONICAL =
;
The code above replaces the liveUrl of the default site with the currently opened site and creates HtmlLink element with the canonical (default) url.
The result will be:
<link rel=
href=
"http://www.sitefinity.com/documentation/user-guide"
Now you can build the application.
4. Register your control in Sitefinity. For more information, see Registering a new widget in Sitefinity.
5. Go to the Page Template that is used by your pages and add the user control in it.
As a result each time you request a page from any of the sites, a link tag will be rendered inside with href with value equal to the canonical URL that you set in the CanonicalMetaTagSetter.
Back To Top
To submit feedback, please update your cookie settings and allow the usage of Functional cookies.
Your feedback about this content is important