Read time: 10 min
This blog post puts the start of a series of SEO best practises.
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:
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:
* 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
- Open the code-behind and put the following code inside:
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:
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.