More AEM/CQ5 SEO Best Practices: Redirects, Vanity URLS, and XML Sitemaps

I'll dive into how you can implement some small, but highly recommended customizations to the "out of the box" features.

This blog post is part of a larger discussion on SEO, and will discuss three more SEO best practices for Adobe Experience Manager (AEM). These specific practices are useful to marketers, for purposes of awareness. I'll also dive a little bit into how you can implement some small, but highly recommended customizations to the "out of the box" features. In this post I'll cover:

  • Appropriate use of the AEM redirect feature
  • How to implement vanity URLs in AEM
  • How you can use AEM to dynamically generate your Sitemap XML file

If you're looking for more tips, make sure to visit my other post about SEO best practices in AEM.

Using 301 Redirects

The "redirect" feature in AEM allows a content author to specify that the page residing at some location now exists in a new location. Using the redirect feature is a good alternative to deleting, deactivating, or moving a page. Without using redirects, in both of those cases, the URL to the old location would produce a "404 - Not Found" response. Bookmarks, links, and search engine crawlers will then all fail to find the resource. Redirecting the page tells all of those external systems where the page went. But, there are two issues to be aware of with the AEM "redirect" feature.

First, if you do this often, your page hierarchy can get a little unwieldy. You would end up with a lot of pages that aren’t technically pages; they are holders for redirects. You may even end up with some pages redirected multiple times. You’ll need to enforce some governance. How long will "redirect" pages remain active? Who is responsible for maintaining them? How/when will they be removed completely? These are all questions you'll need to answer.

Second, the AEM redirect feature uses 302 (moved temporarily) redirects. This is not the appropriate way to handle most redirect scenarios. It's also not the SEO-friendly way to handle it, because search engines will not continue to crawl a link that returns a 302. This is appropriate for truly temporary content, but not if you are permanently moving a page. In that case, you definitely want Google.

// location is the 'page to redirect to'
if (!location.equals(currentPage.getPath())) {
    try {
        SlingSettingsService slingSettings = sling.getService(SlingSettingsService.class);
        if (slingSettings.getRunModes().contains("publish")) {
            response.setHeader("Location", location + ".html");
            response.setHeader("Connection", "close");
    } catch (Exception e) {
        // Do nothing, just try with a 302.
    response.sendRedirect(request.getContextPath() + location + ".html");

Vanity URLs

AEM provides a vanity URL feature to authors who want to generate shortened URLs. This one is an easy best practice: don’t use this feature. It uses Sling mapping to generate said vanity URL and there a two big problems with this.

First, it assumes that all of your redirecting, rewriting, and forwarding happens at the Apache Sling level. That means you aren’t caching any pages with the dispatcher, nor are you relying on your web server to do what it’s meant to do. Without caching, your application will likely have performance issues. I’m also pretty confident you’ll find that Sling mapping will not be sufficient for managing all request resolution for your site.

Second, this approach creates the potential for duplicate URLs, which will get you penalized by search engines. If I have a page a /services/aem.html and I create a vanity URL and /aem, both of those will provide 200 responses to the same content. Google doesn’t like that. As a general best practice, you only want to have one URL per resource. All other “paths” to that resource should either 301 redirect or canonically link to that single, “master” resource.

There are always exceptions to the rule. But, as a general best practice, you should only allow your web server to define public-facing vanity URLs and they should always 301 redirect to the actual resource.

Business stuff doing business things.