Shorten the Sitemap generated url | Community
Skip to main content
Level 5
April 20, 2026
Question

Shorten the Sitemap generated url

  • April 20, 2026
  • 1 reply
  • 15 views

Using the OOTB sitemap for the generation. Added the generated screenshot below. loc url should be starts with /us/en and .html should be removed. I followed the this url as well not working as expected. Sitemaps | Adobe Experience Manager
Any comments or suggestion will be helpful Thanks in advance. 

 

    1 reply

    PGURUKRISHNA
    Level 5
    April 21, 2026

    Hey ​@aravindS The Sling Mappings are the prerequisite — without them working correctly on publish, even the custom generator won't strip the 

    /content/<site>

     prefix. Test your mappings first by hitting 

    http://localhost:4503/system/console/jcrresolver

     and verifying the map output. Here's the complete solution. You need two things:

    1. Sling Mapping Config

    Create this in your 

    ui.config

     module under 

    config.publish

     runmode:

     

    org.apache.sling.jcr.resource.internal.JcrResourceResolverFactoryImpl.cfg.json
    {
    "resource.resolver.mapping": [
    "/:/",
    "/content/<your-site>/:/",
    ]
    }

     

    Replace 

    <your-site>

     with your actual site name. This makes 

    resolver.map()

     strip 

    /content/<your-site>

     so URLs become 

    /us/en/...

    .

    2. Custom Extensionless SitemapGenerator

    Create this Java class in your 

    core

     module:

    package com.mysite.core.sitemap;

    import com.day.cq.wcm.api.Page;
    import com.day.cq.wcm.api.PageFilter;
    import com.day.cq.wcm.api.PageManager;
    import org.apache.sling.api.resource.Resource;
    import org.apache.sling.api.resource.ResourceResolver;
    import org.apache.sling.sitemap.SitemapGenerator;
    import org.apache.sling.sitemap.builder.Sitemap;
    import org.osgi.service.component.annotations.Component;

    import java.util.Iterator;
    import java.util.Set;

    @Component(service = SitemapGenerator.class, property = {
    "service.ranking:Integer=100"
    })
    public class ExtensionlessSitemapGenerator implements SitemapGenerator {

    @Override
    public Set<String> getNames(Resource resource) {
    return Set.of(DEFAULT_SITEMAP);
    }

    @Override
    public void generate(Resource resource, String name, Sitemap sitemap,
    Context context) throws Exception {
    ResourceResolver resolver = resource.getResourceResolver();
    Page rootPage = resolver.adaptTo(PageManager.class).getContainingPage(resource);
    if (rootPage == null) return;

    addPage(sitemap, rootPage, resolver);
    Iterator<Page> children = rootPage.listChildren(new PageFilter(), true);
    while (children.hasNext()) {
    addPage(sitemap, children.next(), resolver);
    }
    }

    private void addPage(Sitemap sitemap, Page page, ResourceResolver resolver) throws Exception {
    if (page.isHideInNav()) return;

    String loc = resolver.map(page.getPath() + ".html");
    if (loc.endsWith(".html")) {
    loc = loc.substring(0, loc.length() - 5);
    }

    var url = sitemap.addUrl(loc);
    if (page.getLastModified() != null) {
    url.setLastModified(page.getLastModified().toInstant());
    }
    }
    }

     

    3. Enable Sitemap on your site root

    On your site root page (e.g. 

    /content/mysite/us/en

    ), ensure these properties are set:

    •  

      sling:sitemapRoot
       = 
      true

    Result

    Before:

    <loc>https://www.mysite.com/content/mysite/us/en/page.html</loc>

     

    After:

    <loc>/us/en/page</loc>

     

    Note: If you want fully qualified URLs (e.g. 

    https://www.mysite.com/us/en/page
    ), configure the Externalizer via 
    com.day.cq.commons.impl.ExternalizerImpl.cfg.json
     or include the domain in your Sling Mapping like 
    "resource.resolver.mapping": ["/content/mysite/:/", "https://www.mysite.com/:/"]
    .

     

     

    Pagidala GuruKrishna