'How to customise the default language sitemap url in a multilanguage Hugo website

I have a multilanguage website in Hugo and right now the sitemap generated automatically is the following:

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
   <loc>https://domain/en/sitemap.xml</loc>
   <lastmod>2022-04-20T08:34:57+02:00</lastmod>
  </sitemap>
  <sitemap>
   <loc>https://domain/it/sitemap.xml</loc>
   <lastmod>2022-04-20T08:34:57+02:00</lastmod>
  </sitemap>
</sitemapindex>

The issue is that all the content in English, which is the default language, does not contain /en in the url but simply the slug itself, such as /products /blog. The italian content contains the language indication in the url instead, such as /it/prodotti, /it/blog.

Sitemap-wise, it doesn't seem to be advisable to have the english sitemap in /en/sitemap. It should be in /domain/sitemap_en.xml instead.

Any clue on how to customise the localised url of the sitemap?

Thank you.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source