To code your JSPs to render canonical URLs, you use the URL recoding feature described in the URL Recoding section. The canonical URL generated for a page is similar to the static URL rendered for web spiders by an indirect URL template. The canonical URL should always be static, regardless of whether the page is accessed by a spider or a human user. That way, if a spider happens to access a page using a dynamic URL (e.g., by following a link from another page), it will still see (and record) the static URL it finds in the link
tag. As with the URL recoding feature, when a user accesses a page via a static URL, the SEO jump servlet translates it back to its dynamic equivalent for processing.
To render canonical URLs, you use the atg.repository.seo.CanonicalItemLink
servlet bean. This class is similar to the ItemLink
servlet bean, except that it does not use template mappers, because the URL template used does not depend on the browser type of the request. So rather than configuring the ItemLink
servlet bean’s itemDescriptorNameToMapperMap
property to map item descriptors to UrlTemplateMapper
components, you configure the CanonicalItemLink
servlet bean’s itemDescriptorNameToUrlTemplateMap
property to map item descriptors directly to UrlTemplate
components. For example:
itemDescriptorNameToUrlTemplateMap=\ product=/atg/repository/seo/ProductIndirectTemplate,\ category=/atg/repository/seo/CategoryIndirectTemplate
The following example illustrates using the CanonicalItemLink
servlet bean on a product detail page to render a link
tag specifying the page’s canonical URL:
<dsp:droplet name="/atg/repository/seo/CanonicalItemLink"> <dsp:param name="id" param="productId"/> <dsp:param name="itemDescriptorName" value="product"/> <dsp:param name="repositoryName" value="/atg/commerce/catalog/ProductCatalog"/> <dsp:oparam name="output"> <dsp:getvalueof var="pageUrl" param="url" vartype="java.lang.String"/> <link rel="canonical" href="${pageUrl}"/> </dsp:oparam> </dsp:droplet>
For additional information about the CanonicalItemLink
servlet bean, see the Page Developer's Guide.