Notes to self

Combining multiple sitemaps with a sitemap index

What if we need to combine multiple sitemaps for a main domain or subdomain? Here’s how to do it by creating sitemap index.

Sitemap index

Let’s say our site has a regular sitemap.xml and a blog/sitemap.xml, but we want Google to crawl and index both. To combine them we need to rename the original to something else like main_sitemap.xml and then create an index of all sitemaps we have:

<?xml version="1.0" encoding="UTF-8"?>

<sitemapindex xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
  <sitemap>
     <loc>https://deploymentfromscratch.com/main_sitemap.xml</loc>
     <lastmod>2004-10-01T18:23:17+00:00</lastmod>
   </sitemap>
   <sitemap>
      <loc>https://deploymentfromscratch.com/blog/sitemap.xml</loc>
   </sitemap>
</sitemapindex>

And that’s it, both sitemaps then stay exactly same as before. Optionally we can include <lastmod> tag for latest modification.

Check out my book
Deployment from Scratch is unique Linux book about web application deployment. Learn how deployment works from the first principles rather than YAML files of a specific tool.
by Josef Strzibny
RSS