Modify placement of sitemaps for multilang site

I’d like to modify the default placement of sitemaps. The docs say:

With a multilingual project, Hugo generates:

  • A sitemap.xml file in the root of each site (language) using the built-in sitemap.xml template
  • A sitemap.xml file in the root of the publishDir using the built-in sitemapindex.xml template

However I’d like to change this so it’s instead (differences bolded):

  • A sitemap.xml file in the root of each site (language), except for the default language, using the built-in sitemap.xml template
  • A sitemap.xml file in the root of the publishDir using the built-in sitemap.xml template for the default lang
  • A sitemap_index.xml file in the root of the publishDir using the built-in sitemapindex.xml template which outputs all language sitemaps.

Resulting structure would be:

https://example.com/sitemap.xml = contains only English language URLs on the main domain. This does not need to include the other languages.
https://example.com/es/sitemap.xml = contains all Spanish language URLs
https://example.com/ja/sitemap.xml = etc.
https://example.com/zh/sitemap.xml = etc.
https://example.com/ko/sitemap.xml
https://example.com/de/sitemap.xml
https://example.com/fr/sitemap.xml
https://example.com/es/sitemap.xml
https://example.com/sitemap_index.xml = references all of the XML sitemaps above

Is there a way of doing this without disabling the default sitemaps, and creating a custom output type with corresponding content files?

In your site configuration, what is the value of defaultContentLanguageInSubdir? It defaults to false.

It’s false as it’s not explicitly set in my config.

I cannot come up with a way to do as you ask.

I cannot come up with a way to do as you ask.

Hopefully not because of my poor placement of “the” in the sentence you quoted. :laughing:

Yeah, I suspected that there may not be a way.

Next best thing:

With the custom sitemap route, creating a custom output type and creating a section for sitemaps in the content folder, is there a way for it to automatically generate a page for every language without manually creating a sitemap.{lang}.xml file for each language?

Regardless of approach, this seems like a lot of work. What happens if you do nothing? Can you use server-side redirects instead?

Edit: you can’t use a redirect for the sitemap_index because it would have the wrong path to the en version.

It may be that doing nothing is fine. Fact finding at the moment based on the requested structure from our SEO consultant.

This sounds like the better option.

1 Like