Externalizing URLs for a sitemap | Community
Skip to main content
Level 4
March 16, 2017
Solved

Externalizing URLs for a sitemap

  • March 16, 2017
  • 3 replies
  • 4706 views

I have a servlet on my page template at sitemap.xml.jsp that I'm using to generate a sitemap dynamically. I'm running into an issue with the display of the urls. 

The output currently displays like: 

<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"> <url> <loc>http://dispatcher.localhost:8080/content/online/</loc> <lastmod>2017-03-15</lastmod> <priority>1</priority> </url> <url> <loc> http://dispatcher.localhost:8080/content/online/academics </loc> <lastmod>2017-02-23</lastmod> <priority>0.667</priority> </url> <url> <loc> http://dispatcher.localhost:8080/content/online/apply-today </loc> <lastmod>2017-02-24</lastmod> <priority>0.667</priority> </url> <url> <loc> http://dispatcher.localhost:8080/content/online/cincinnati-online-experience </loc> <lastmod>2017-01-02</lastmod> <priority>0.667</priority> </url> ...

As you can see in the <loc> element, instead of the domain (in this case http://online.uc.edu) it's showing a dispatcher url along with the /content/online 

A correct URL would be http://online.uc.edu/cincinnati-online-experience

I'm using externalizer.absoluteLink(), but that doesn't seem to be working in this case. Heres the relevent parts of my jsp file:

public Element getPageNode(Page page, Document doc, Externalizer externalizer, ResourceResolver resourceResolver, SlingHttpServletRequest request,int ogDepth) { //Create a result element Element url = doc.createElement( "url" ); Element loc = doc.createElement( "loc" ); loc.appendChild( doc.createTextNode( externalizer.absoluteLink(request, request.getScheme(),  page.getPath()))); url.appendChild( loc ); return url; }

Do I need to change a setting in the externalizer config to make the absolute link work?

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by daniel_henriqu1

Hi, Ben.

Yes, there is a specific setting for Externalizer: http://<host>:<port>/system/console/configMgr/com.day.cq.commons.impl.ExternalizerImpl

You can configure a "domain" and use its name as the second parameter of externalLink call.

For further info, please check: https://docs.adobe.com/docs/en/aem/6-2/develop/platform/externalizer.html

Be aware that some Sling Mappings may also influence the links generated by the Externalizer.

Regards,

Daniel.

3 replies

daniel_henriqu1
daniel_henriqu1Accepted solution
Level 4
March 16, 2017

Hi, Ben.

Yes, there is a specific setting for Externalizer: http://<host>:<port>/system/console/configMgr/com.day.cq.commons.impl.ExternalizerImpl

You can configure a "domain" and use its name as the second parameter of externalLink call.

For further info, please check: https://docs.adobe.com/docs/en/aem/6-2/develop/platform/externalizer.html

Be aware that some Sling Mappings may also influence the links generated by the Externalizer.

Regards,

Daniel.

April 15, 2022

Be aware that some Sling Mappings may also influence the links generated by the Externalizer.

How it will influence?

In externalizer in set the domain name as www.abc.com.

In etc.dev.publish, i have sling mappings with 2 domains: 1. www.xyz.com  and www.abc.com

When sitemap is generating, it is generating the urls with www.xyz.com/home. How can i avoid it?

Anton_Smulskiy
Level 3
March 16, 2017

Try externalizer.externalLink(..). Make sure you have configuration for Externalizer domain

daniel_henriqu1
Level 4
March 16, 2017

Or you can simply use Sling Mappings (reverse mapping) and ResourceResolver.map to achieve the same result.

Regards,

Daniel.