Saturday, July 31, 2021

Sitemap.xml in AEM Cloud

An XML sitemap is a file that lists a website’s important pages, making sure Google and other search engines can find and crawl them all. It also helps search engines understand your website structure. Though search engines crawls all pages and links in the page, seldom sites end up with few pages that are not linked from any other pages (like the promo landing pages). Having those pages entered in sitemap.xml, speeds up the content discovery and get indexed.

This blog narrates the implementation of sitemap.xml using ACS AEM Commons  package. ACS AEM Commons package is open source package, originally built and supported by Adobe Consulting Services, later turned into an open source/AEM community maintained package. 

You can get more details on this and other features provided by package here 

Lets walk through the steps in implementing the sitemap.xml using this package.

  1. Create a OSGI Configuration for sitemap servlet.
    • create a file com.adobe.acs.commons.wcm.impl.SiteMapServlet-custom.cfg.json under ui.config/config. This setting will be common for all run modes.
    • Edit file with necessary parameters
    • sling.servlet.resourceTypes - This should have path to the page component in your project
    • externalizer.doain - this should have the domain name or the site name

  2. Create a OSGI Configuration for Externalizer Implementation
    • create a file com.day.cq.commons.impl.ExternalizerImpl.cfg.json.
    • This file should be created for each run mode (dev, qa, stage, prod) as the value will change for each environment
    • Entries have various site/domains and its relative URL - local, author and publish are updated by default by AEM.
    • add the new site and its url

Build and Deploy the changes to AEM instance. Now request to any page with .sitemap.xml should render the sitemap for the page.

Additionally, you can make dispatcher rewrite rule for /sitemap.xml to redirect to site home page with extention ".sitemap.xml" - ex: /content/<site>/us/en.sitemap.xml where en is the root home page for the site. This will generate sitemap with links to all pages in the site starting from root page and drill down to all child level pages.

No comments:

Post a Comment