Search code examples
reactjsseomultilingualxml-sitemap

Dynamic sitemap by language


I have several static sitemap (one sitemap for one language, ie sitemap_en.xml, sitemap_de.xml) and i want to deserve a final static sitemap.xml (http://example.com/sitemap.xml) which targets good sitemap depending on language (http://example.de/sitemap.xml --> sitemap_de.xml)

I am wondering how to do that in a react app, on a ssr way i can do

app.get('/sitemap.xml', function(req, res) {
  res.sendFile('good_path_to_correct_sitemap.xml');
});

Maybe there is a better solution to handle several static sitemap in a multilingual website with multi domains


Solution

  • You need to centralize all of your sitemaps into one sitemap index, quoting:

    If you have many sitemaps, you can use a sitemaps index file as a way to submit them at once. The XML format of a sitemap index file is very similar to the XML format of a sitemap file.

    But in your case, since each language is served on a different domain, you can do a cross submit, quoting:

    By default, this will result in a "cross submission" error since you are trying to submit URLs for www.host1.com through a Sitemap that is hosted on www.sitemaphost.com (and same for the other two hosts). One way to avoid the error is to prove that you own (i.e. have the authority to modify files) www.host1.com. You can do this by modifying the robots.txt file on www.host1.com to point to the Sitemap on www.sitemaphost.com.