1. Home
  2. Knowledge Base
  3. SEO Suite
  4. Why the Sitemap_Index.xml is Throwing a 404 Error

Why the Sitemap_Index.xml is Throwing a 404 Error

The sitemap_index.xml file is used by Google to keep track of all the pages on your site. If this sitemap is unavailable and returns a 404 error, then Google won’t be able to find all the pages on your site.


In this knowledgebase article, we’re going to walk you through why the sitemap_index.xml throws a 404 error and how to solve this issue.

1 Why Does the Sitemap_index.xml Throw a 404 Error?

A 404 error basically means that the sitemap index or individual sitemap does not exist. Google bot expects a result of 200 ok responses & fetches all your website URLs via submitted sitemap file. Instead, it throws a 404 error when it cannot locate the sitemap_index.xml.

Configuring sitemaps in Rank Math is extremely simple. However, if you’re not able to use the sitemap functionality in Rank Math, please go through our knowledgebase article on Rank Math sitemap issues and their fixes that’ll help you to fix some of the common sitemap problems.

2 What Causes a Sitemap_Index.xml File to Throw a 404 Error?

There are a few reasons that can cause the sitemap_index.xml file to throw a 404 error:

  • Permalink Structure: If you recently changed your permalink structure, make sure that you update your sitemap_index.xml file accordingly.
  • Rewrite Rules are Missing: If you are using an NGINX server or Apache server, make sure that you have the correct rewrite rules in place.
  • Sitemap from Caching Plugin: If you are using a caching plugin, make sure that you have excluded the sitemap_index.xml file from being cached. The cache could be via a plugin or from the server.

3 How to Fix sitemap_index.xml Throws a 404 Error in Rank Math?

If you’re using Rank Math and your sitemap_index.xml file is throwing a 404 error, here are a few things that you can do to fix the issue:

3.1 Flush the Sitemap Cache

Once you’ve added the rewrite rules, you need to flush the sitemap cache for the changes to take effect. To do that, navigate to Rank Math > Sitemap Settings and change the Links Per Sitemap as shown below:

Sitemap Settings

Next, click on Save Changes located at the bottom of the page. Once you’ve saved the settings, head over to your WordPress admin area and navigate to Settings > Permalinks as shown below:

Permalink Settings in WordPress

Simply hit the Save Changes button once, even if you didn’t make any changes on the page.

Save Changes

This will flush the permalinks setting and fix your sitemap problem.

3.2 Fix Sitemap Issues on Nginx or Apache Server

If your Nginx server is preventing the creation of the sitemap file, then Rank Math would also let you know through a notice under Sitemap Settings.

For further ado, see the screenshot below:

Sitemap Issues on Nginx Server

In that case, you need to manually add the rewrite rules.

3.2.1 Add Rewrite Rules to Nginx Server

If you’re using an Nginx server, you need to add the following rewrite rules to fix this:

# START Nginx Rewrites for Rank Math Sitemaps
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
# END Nginx Rewrites for Rank Math Sitemaps

Important Note: If you’re not sure about adding these rules, please contact your server administrator or hosting support and they will be able to help you out.

3.2.2 Add Rewrite Rules to Apache Web-Server

Rank Math creates a virtual Sitemap dynamically when you enable that module. We rely on redirects enabled by your server software to accomplish that. If the Sitemap doesn’t work, you may have to add some rewrite rules in your .htaccess file.

You can learn more about How to Edit Your .htaccess File Using Rank Math. Just copy and paste the following code at the end of your .htaccess file:

# START of Rank Math Sitemap Rewrite Rules
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 [L]
# END of Rank Math Sitemap Rewrite Rules

3.3 Exclude the Sitemap Files in the Caching Plugin

Using caching plugins is probably the easiest way to speed up your WordPress site. However, you might end up getting your sitemap cached too, and this is definitely not a good idea! A sitemap should always reflect the latest posts and URLs of your website; caching it defeats the purpose.

Since you don’t have to cache the sitemaps, exclude the sitemap files generated by Rank Math plugin from being cached in your caching plugin. The cache could be via a plugin or from the server.

And, that’s it! Now open the sitemap after clearing your browser’s cache or using a private (incognito) window, and you should see your sitemap without any trouble.

3.4 Add Filter to Enable/Disable Sitemap Caching

Sometimes the sitemap can be affected by the server-level cache. In such a case, you can add the following code to your theme’s functions.php file or rank-math.php file to make sure your sitemap is excluded from caching:

 * Filter if XML sitemap transient cache is enabled.
 * @param boolean $unsigned Enable cache or not, defaults to true
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');

Once done, you can save the changes and re-check your sitemap to see if the issue has been resolved. If the problem persists, you can try the next method.

We hope this article has helped you fix sitemap_index.xml that’s throwing a 404 error in Rank Math. If you have any doubts or questions related to this matter, please don’t hesitate to reach out to our support team. We are available 24×7, 365 days a year, and are happy to help you with any issues that you might face.

Was this article helpful?

Still not using Rank Math?

Setup takes less than 5 minutes including the import from your old SEO Plugin!

Learn more about the PRO Version

Still need help?


Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket

Related Articles