40+ Websites, One Sitemap Problem
After a Sitecore upgrade, the XML sitemaps on more than 40 brand websites started returning 404s. It looked like an SEO problem on 40 sites. It was really one configuration problem on one platform.
The upgrade went fine. Mostly.
We upgraded our Sitecore SXA platform from 10.2 to 10.4. The sites came up, pages rendered, and everyone exhaled. Then the sitemaps started returning 404s.
A sitemap is the XML file that tells search engines which pages a site has. Nobody visits it on purpose, so nobody notices when it breaks. Search engines notice, though. If they can't read it, new and updated pages get discovered more slowly, and that adds up across a whole portfolio of brands.
Forty sites, one pattern
The tempting move is to start fixing sites one at a time. But more than 40 sites broke at the same moment, in the same way, right after the same change. That's not 40 problems. That's one problem showing up 40 times.
So I stopped looking at individual sites and started looking at what they all shared: the platform configuration the upgrade had just touched.
How SXA serves a sitemap
In SXA, a request for /sitemap.xml isn't a file on disk. Sitecore has to recognize the request and hand it to its sitemap handler, which builds the XML on the fly. To build the right XML, it also has to know which site the request belongs to. That comes from the site definitions, which map hostnames to sites.
So there are two separate steps that both have to work, and either one failing gives you the same 404.
Crawler requests /sitemap.xml
↓
1. Is the sitemap handler registered to claim it? ← broke in the upgrade
↓
2. Which site does this hostname belong to? ← broke in the upgrade
↓
Generate that site's sitemap XMLTwo things the upgrade changed
The first problem was the handler. After the upgrade, the SXA sitemap handler wasn't registered correctly in the request pipeline. The request came in, nothing claimed it, and the crawler got a 404.
The second problem was in the site definitions. Some hostName and targetHostName values carried over from the old version were inconsistent. Even with the handler working, a sitemap request has to resolve to the right site before it can return that site's pages.
Telling the two causes apart
Because both problems produce the same 404, the useful skill is separating them. A few checks do that:
- Request /sitemap.xml on more than one site. If every site fails, suspect something platform-wide, like the handler.
- Compare the hostname a request arrives on with the hostName and targetHostName in that site's definition.
- Check the site's SXA sitemap settings in the content tree to make sure sitemap generation is enabled.
- Look for IIS URL rewrite rules that might grab /sitemap.xml before Sitecore sees it.
The fix
I corrected the sitemap handler registration and fixed the hostname settings in the affected site definitions. Then I confirmed the sitemaps were returning real XML instead of 404s across the affected sites.
Because the cause was shared, so was the fix. Correct it once at the platform level, and every site benefits.
What I took away
Upgrades are a lot like moving. Everything makes it to the new house, but it takes a few days to notice the box with the forks in it never got unpacked.
- When dozens of sites break the same way, look at what they share before touching any one of them.
- After an upgrade, check the things nobody looks at, like sitemaps, robots files, and error pages. They break quietly.
- A request has to be claimed by the right handler and matched to the right site. Check both steps.
- SEO problems can be platform problems wearing a marketing hat.