I've created a sitemap XML for our site using Apache Sling Sitemap - Sitemap Generator Manager. However, I'm looking for a way to change the hostname in this section: <loc>http://localhost:4502/content/blablabla/us.sitemap.test7-sitemap.xml</loc>. I want to remove the /content part. Any suggestions?"
Solved! Go to Solution.
Views
Replies
Total Likes
Hi @Ayoub_Tabai
To overwrite the hostname while generating a sitemap XML using Apache Sling Sitemap - Sitemap Generator Manager and remove the /content part from the <loc> section, you can achieve this by configuring the Sitemap Manager to use a custom servlet resolver.
Create a Custom Servlet Resolver: Implement a custom servlet resolver that modifies the generated sitemap URLs.
Register the Custom Servlet Resolver: Register the custom servlet resolver with the appropriate configurations.
Here's how you can do it:
import org.apache.sling.sitemap.SitemapGeneratorManager;
import org.apache.sling.sitemap.SitemapResolver;
import org.apache.sling.sitemap.spi.generator.SitemapGenerator;
import org.apache.sling.sitemap.spi.generator.SitemapGeneratorFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component(service = SitemapResolver.class)
public class CustomSitemapResolver implements SitemapResolver {
@Reference
private SitemapGeneratorFactory sitemapGeneratorFactory;
@Override
public SitemapGenerator resolve(String sitemapName) {
SitemapGenerator generator = sitemapGeneratorFactory.createGenerator(sitemapName);
if (generator != null && generator.getGeneratorId().equals("sling:basic")) {
// Customize the generator's URLs here
generator.setHostname("your-custom-hostname.com");
}
return generator;
}
}
In this custom resolver:
Make sure to replace "your-custom-hostname.com" with your actual hostname.
Once you've created and registered the custom resolver, it will intercept sitemap generation requests and modify the URLs accordingly, removing the /content part and replacing the hostname.
This approach ensures that the modification is applied dynamically during sitemap generation, without the need to manipulate the generated XML afterward.
Thanks
Hi @Ayoub_Tabai
To overwrite the hostname while generating a sitemap XML using Apache Sling Sitemap - Sitemap Generator Manager and remove the /content part from the <loc> section, you can achieve this by configuring the Sitemap Manager to use a custom servlet resolver.
Create a Custom Servlet Resolver: Implement a custom servlet resolver that modifies the generated sitemap URLs.
Register the Custom Servlet Resolver: Register the custom servlet resolver with the appropriate configurations.
Here's how you can do it:
import org.apache.sling.sitemap.SitemapGeneratorManager;
import org.apache.sling.sitemap.SitemapResolver;
import org.apache.sling.sitemap.spi.generator.SitemapGenerator;
import org.apache.sling.sitemap.spi.generator.SitemapGeneratorFactory;
import org.osgi.service.component.annotations.Component;
import org.osgi.service.component.annotations.Reference;
@Component(service = SitemapResolver.class)
public class CustomSitemapResolver implements SitemapResolver {
@Reference
private SitemapGeneratorFactory sitemapGeneratorFactory;
@Override
public SitemapGenerator resolve(String sitemapName) {
SitemapGenerator generator = sitemapGeneratorFactory.createGenerator(sitemapName);
if (generator != null && generator.getGeneratorId().equals("sling:basic")) {
// Customize the generator's URLs here
generator.setHostname("your-custom-hostname.com");
}
return generator;
}
}
In this custom resolver:
Make sure to replace "your-custom-hostname.com" with your actual hostname.
Once you've created and registered the custom resolver, it will intercept sitemap generation requests and modify the URLs accordingly, removing the /content part and replacing the hostname.
This approach ensures that the modification is applied dynamically during sitemap generation, without the need to manipulate the generated XML afterward.
Thanks
Follow below blog to have sitemap and shortened url
https://medium.com/@toimrank/aem-sitemap-externalize-and-extension-less-url-be916490d2c6
Views
Likes
Replies
Views
Likes
Replies