/ โ† Robots and Sitemap Fixes / sitemap_index.xml in WordPress
In this guide
  1. Which sitemap address your site should have
  2. What each symptom usually means
  3. How to diagnose it
  4. Rewrite rules and nginx
  5. Finding stray output and cache problems
  6. A worked example
  7. The fix, step by step
  8. Edge cases worth knowing
  9. Keeping it fixed
  10. Questions and answers

Which sitemap address your site should have

Since WordPress 5.5, core generates a sitemap at /wp-sitemap.xml. SEO plugins that build their own sitemaps turn the core one off and use a different address. Asking for the wrong address is the most common reason a sitemap seems missing:

SetupSitemap index addressWhere to switch it on
WordPress core, no SEO plugin sitemap/wp-sitemap.xmlOn by default when the site is visible to search engines
Yoast SEO/sitemap_index.xmlYoast SEO, Settings, Site features, XML sitemaps
Rank Math/sitemap_index.xmlRank Math dashboard, Sitemap module, then Sitemap Settings
Other sitemap pluginsOften /sitemap.xmlThe plugin's own settings

If you switch a plugin's sitemap off, its address stops working and the core sitemap usually returns. If you remove the plugin entirely, the same happens. Requests for /sitemap.xml are redirected to whichever index is active in many setups, so that address is a useful test but not a guarantee.

The index itself contains no pages. It lists child sitemaps, such as post-sitemap.xml and page-sitemap.xml in Yoast and Rank Math, or wp-sitemap-posts-post-1.xml in core. A working index with broken children is a separate problem worth checking too.

What each symptom usually means

SymptomMost likely cause
WordPress-styled 404 pageStale rewrite rules, sitemap feature off, or the wrong address
Plain nginx 404 pagenginx handled the request itself and never passed it to WordPress
XML declaration allowed only at the start of the documentSomething printed output, often a blank line, before the XML
Blank white pageA PHP error, a memory limit, or a cache storing an empty response
Page loads as HTML or shows page markupA caching or minification plugin rewrote the XML
Old URLs or missing new postsThe sitemap or a page cache is serving a stale copy
Redirect to the home page or another sitemapTwo sitemap generators competing, or a redirect rule catching the address

Look at the page itself first. A WordPress-styled error page means WordPress received the request and decided nothing matched. A bare page with nginx at the bottom means WordPress never saw it, which points at the server configuration rather than any setting inside WordPress.

How to diagnose it

Request the index and look at the status line, content type and the very first bytes of the body:

curl -sI https://www.example.com/sitemap_index.xml
curl -s https://www.example.com/sitemap_index.xml | head -c 80 | od -c | head -n 3

A healthy response is 200 with a content type of text/xml or application/xml, and the body starts with <?xml. If od shows \n or a space first, a line break or space was printed before the declaration. If it shows 357 273 277, the octal form of a UTF-8 byte order mark, a PHP file was saved with a BOM.

Then test with caches out of the way. Add a throwaway query string, such as ?nocache=1, and compare. If the fresh request works and the plain one does not, a cache is serving a broken copy. Request one child sitemap too, because a broken child can fail on its own.

In a browser, view the source of the sitemap rather than the styled view. Yoast and Rank Math attach an XSL stylesheet that makes the sitemap look like a web page, which can hide what is really at the top of the file. If Search Console reports the sitemap as unreadable, see Sitemap could not be read for the checks Google applies.

Rewrite rules and nginx

Yoast and Rank Math sitemaps are not files on disk. They are built by WordPress when a request arrives, so the server has to pass the request to WordPress. On Apache, the standard WordPress block in .htaccess does that, and saving Settings, then Permalinks, rebuilds both WordPress's internal rules and that block when the file is writable.

nginx does not read .htaccess. The server block needs a try_files line that sends anything that is not a real file to index.php:

location / {
    try_files $uri $uri/ /index.php?$args;
}

With that in place, WordPress usually handles /sitemap_index.xml on its own. The trouble starts when another location block matches the address first. Many configurations include a block like this for static files:

location ~* \.(xml|txt|css|js|png|jpg|svg)$ {
    expires 30d;
    try_files $uri =404;
}

Because regex locations take priority over location /, any address ending in .xml is looked up on disk, not found, and answered with nginx's own 404. Either remove xml from that list, change =404 to /index.php?$args, or add the rewrite lines that Yoast and Rank Math both document for nginx above it:

rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

Check the current wording in your plugin's documentation, since plugins occasionally change their query names. After any edit, run sudo nginx -t and then sudo systemctl reload nginx. On Plesk, add custom directives under Apache and nginx Settings for the domain rather than editing generated files, which are overwritten. For nginx redirects more generally, see fixing redirects in Plesk.

Finding stray output and cache problems

The XML declaration must be the first thing in the response. Chrome reports a violation as XML declaration allowed only at the start of the document, and Firefox as XML or text declaration not at start of entity. The usual source is a PHP file that ends with ?> followed by a blank line, or a file saved with a byte order mark. Every request then starts with that stray character, which is harmless in HTML and fatal in XML.

To find a BOM in theme and plugin files, run this from the WordPress root:

grep -rlI --include='*.php' $'^\xEF\xBB\xBF' wp-content/themes wp-content/plugins wp-config.php

For blank lines after a closing tag, open the files you or a developer edited recently, starting with the child theme's functions.php. Remove the closing ?> at the end of the file altogether; PHP does not need it, and leaving it out prevents the problem. If you cannot see the culprit, test by elimination with WP-CLI, which avoids clicking through the dashboard:

wp theme activate twentytwentyfive
wp plugin deactivate plugin-name

Reload the sitemap after each change, and switch everything back once you have found the file responsible.

Caching and minification

Page caching and HTML minification plugins sometimes store or rewrite the sitemap as if it were a page. Add sitemap and .xml to the cache exclusions, switch off minification for those addresses, then purge. Yoast and Rank Math also keep their own sitemap cache; turning the sitemap feature off, saving, turning it back on and saving again refreshes it. If a CDN cache rule caches everything, exclude sitemap addresses there too. The sitemap lastmod guide explains why a stale copy also misleads crawlers about what has changed.

A worked example

A WordPress site moves from shared Apache hosting to a VPS running nginx. The home page loads normally, so the move looks finished. A week later, Search Console reports the sitemap as unreadable. Opening /sitemap_index.xml shows a plain 404 page with nginx at the bottom.

The plain page shows WordPress never saw the request. The new server block, copied from a static site template, has no try_files line in location /, so only the home page, which nginx passes to index.php as the index file, ever reaches WordPress. Adding location / { try_files $uri $uri/ /index.php?$args; }, running nginx -t and reloading brings the sitemap back.

A check of other addresses shows posts, category archives and the feed had also been returning 404 since the move. Visitors mostly arrived on the home page, so nobody had noticed. The sitemap was the first thing reported, not the only thing broken.

The fix, step by step

Step 1

Confirm which sitemap you should have

Check whether Yoast SEO, Rank Math or another plugin is generating sitemaps, and whether its sitemap feature is switched on. With Yoast or Rank Math active, the address is /sitemap_index.xml; with neither, it is /wp-sitemap.xml from WordPress core. Request both with curl -sI and note which returns 200. If the one you expected is off, switch it on in the plugin settings, save, and test again before changing anything else.

Step 2

Read the response and first bytes

Run curl -sI on the sitemap index to see the status and content type, then pipe the body through head -c 80 and od -c to see the first bytes. The body must start with the XML declaration. A leading line break, space or byte order mark means stray output. Note whether a 404 page looks like WordPress or plain nginx, because that tells you whether WordPress ever received the request at all.

Step 3

Refresh permalinks

In the WordPress dashboard, open Settings, then Permalinks, and click Save Changes without altering anything. This rebuilds WordPress's rewrite rules and, on Apache, the WordPress block in .htaccess if the file is writable. Then toggle the plugin's sitemap feature off, save, back on and save again to refresh its sitemap cache. Reload /sitemap_index.xml and confirm it returns 200. This alone fixes most 404s after a plugin change or migration.

Step 4

Fix the nginx configuration

If the 404 page is a plain nginx page, open the server block. Make sure location / contains try_files $uri $uri/ /index.php?$args;. Look for regex location blocks matching .xml with try_files $uri =404; and remove xml from them, or add the sitemap rewrite lines from the plugin's documentation above them. Run sudo nginx -t, reload nginx, and request the sitemap index and one child sitemap to confirm both return 200.

Step 5

Remove stray output before the XML

If the browser reports that the XML declaration is only allowed at the start of the document, search theme and plugin PHP files for a byte order mark with grep, and check recently edited files for a blank line after a closing ?> tag. Delete the closing tag at the end of the file. If the culprit is not obvious, switch to a default theme, then deactivate plugins one at a time with WP-CLI, reloading the sitemap after each.

Step 6

Exclude sitemaps from caching

In your caching or optimisation plugin, add sitemap and .xml to the page cache exclusions and switch off HTML minification for those addresses. Do the same for any CDN rule that caches everything. Purge all caches, then request the sitemap with and without a throwaway query string such as ?nocache=1. Both responses should be identical, return 200 and contain your latest posts, which shows the copy is no longer stale.

Step 7

Keep one sitemap generator

If two plugins can generate sitemaps, such as two SEO plugins or an SEO plugin plus a sitemap plugin, choose one and switch the sitemap feature off in the others. Deactivate any plugin you no longer use. Then refresh permalinks once more. Request /sitemap_index.xml, /wp-sitemap.xml and /sitemap.xml and check that only one index is served, with the others returning 404 or redirecting to it.

Step 8

Resubmit and declare the sitemap

Once the index loads as valid XML with a 200 status, open the Sitemaps report in Google Search Console, enter the address and submit it, replacing any old address that no longer works. Add a Sitemap: line with the full address to robots.txt. Check back after a day or two: the report should show a status of Success, a recent read date and the number of URLs Google discovered from it.

Edge cases worth knowing

Keeping it fixed

After any migration, plugin change or server change, open the sitemap index straight away with curl and check for a 200, an XML content type and a body that starts with the declaration. It is often the first thing to break and the last thing anyone checks. Keep one sitemap generator, list its address in robots.txt with a Sitemap: line, and look at the Sitemaps report in Search Console each month for its last read date and status. The sitemap declaration guide covers the robots.txt line, and robots.txt and sitemaps in WordPress covers the wider setup.

Questions and answers

1. Why does sitemap_index.xml show a 404 in WordPress?

A 404 on sitemap_index.xml usually means the rewrite rules are stale, the plugin's sitemap feature is switched off, or the web server never passes the request to WordPress. Start by saving Settings, then Permalinks, without changes, and check that Yoast or Rank Math has its sitemap switched on. If the 404 page is a plain nginx page, the server configuration is the problem, often a missing try_files rule or a static file block that catches every address ending in .xml.

2. What is the difference between wp-sitemap.xml and sitemap_index.xml?

The address wp-sitemap.xml is the sitemap built into WordPress core since version 5.5, while sitemap_index.xml is the address used by SEO plugins such as Yoast SEO and Rank Math. When one of those plugins has its sitemap switched on, it turns the core sitemap off, so only one of the two should work at a time. Use whichever your setup actually serves, submit that one to Search Console, and list it in robots.txt.

3. How do I fix XML declaration allowed only at the start of the document?

That error means something was printed before the XML declaration, usually a blank line or a byte order mark from a theme or plugin PHP file. Check the end of recently edited files, especially functions.php, for a blank line after a closing PHP tag, and remove that closing tag. Search for files saved with a byte order mark. If you cannot find it, switch to a default theme and deactivate plugins one at a time until the sitemap loads.

4. Why is my WordPress sitemap a blank page?

A blank sitemap page usually comes from a PHP error, a memory or time limit on a large sitemap, or a cache that stored an empty response. Check the PHP error log on the server for errors at the time you loaded the sitemap. Purge your caches and request the sitemap with a throwaway query string to bypass them. On large sites, reduce the number of entries per child sitemap in the plugin settings so each one builds within the limits.

5. Do I need nginx rewrite rules for Yoast or Rank Math sitemaps?

Usually not, if your nginx configuration has the standard WordPress try_files rule and no other block catches addresses ending in .xml first. In that case WordPress handles the sitemap addresses itself. The extra rewrite lines that Yoast and Rank Math document are needed when a static file location matches .xml and returns 404 before WordPress runs. Adding them, or fixing that static block, sends the sitemap requests to WordPress where the plugin can build them.

6. Should I use Yoast and Rank Math sitemaps together?

No, you should run only one sitemap generator on a WordPress site. Two plugins trying to serve sitemap_index.xml, or an SEO plugin alongside a separate sitemap plugin, compete for the same address and can produce redirects, missing content or errors. Choose the plugin you use for SEO, keep its sitemap on, and switch off or remove the others. Then refresh permalinks and check that a single sitemap index loads, and resubmit it if the address changed.

7. How long does Google take to read a resubmitted sitemap?

Google often fetches a submitted sitemap within a day or two, though it can take longer and there is no fixed time. The Sitemaps report in Search Console shows the last read date and status once it has been processed. Submitting a sitemap does not guarantee every URL in it will be crawled or indexed; it helps Google discover them. Listing the sitemap in robots.txt as well lets other search engines find it without a separate submission.

Check your sitemap index loads as valid XML

The robots and sitemap checker on aiwebpageseo.com fetches your sitemap index and its child sitemaps, reports status codes and XML errors, and checks the sitemap is declared in robots.txt.

Open Robots and Sitemap Fixes โ†’
๐Ÿ’ฌ Got a problem?
Related Guides: All Robots and Sitemap Fixes  ·  Sitemap could not be read  ·  Robots.txt and sitemaps in WordPress  ·  How to fix sitemap 404s  ·  How to edit robots.txt in WordPress and Cloudflare  ·  Learning Hub

About aiwebpageseo

aiwebpageseo.com is a data-driven SEO and AEO (Answer Engine Optimisation) platform providing a free suite of technical SEO tools. Rather than relying on AI-theorised assumptions, the platform analyses live URL performance, delivering objective diagnostics, page speed metrics, CLS debugging, and site crawl data alongside actionable technical tutorials.