In my previous post, i have discussed about Canonical URLs and its importance in SEO. In this post we will see how to implement Canonical Urls in an Umbraco based site using XSLT Macro.
Umbraco sites have multiple ways of accessing content - either by friendly URL or by direct URL. In such cases to have a proper SEO page ranking, we need to implement Canonical URLs. To achive this in Umbraco based site, we can create an XSLT macro and insert that macro into the <Head> secton while creating templates.
CanonicalUrls.xslt
<?xml version="1.0" encoding="UTF-8"?><!DOCTYPE xsl:Stylesheet [ <!ENTITY nbsp " "> ]><xsl:stylesheetversion="1.0"xmlns:xsl="http://www.w3.org/1999/XSL/Transform"xmlns:msxml="urn:schemas-microsoft-com:xslt"xmlns:umbraco.library="urn:umbraco.library"exclude-result-prefixes="msxml umbraco.library"><xsl:output method="xml" omit-xml-declaration="yes"/><xsl:param name="currentPage"/><xsl:template match="/"><xsl:choose><xsl:when test="starts-with(umbraco.library:RequestServerVariables('HTTP_HOST'),'www')"><xsl:variable name="url" select="concat('http://',umbraco.library:RequestServerVariables('HTTP_HOST'))" /><link rel="canonical" href="{$url}{umbraco.library:NiceUrl($currentPage/@id)}" /></xsl:when><xsl:otherwise><xsl:variable name="url" select="concat('http://www.',umbraco.library:RequestServerVariables('HTTP_HOST'))" /><link rel="canonical" href="{$url}{umbraco.library:NiceUrl($currentPage/@id)}" /></xsl:otherwise></xsl:choose></xsl:template></xsl:stylesheet>
Macro : CanonicalUrls
Usage
This macro can now be inserted into the <Head> section in the template:
<umbraco:Macro Alias="CanonicalUrls" runat="server"></umbraco:Macro>
0 comments
Posts a comment