Beginner's Guide for WordPress - Start your WordPress Blog in minutes.
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
WordPress Plugins
View all Guides

How to Fix Yoast’s WordPress SEO Sitemap 404 Error

Last updated on by
Elegant Themes
How to Fix Yoast’s WordPress SEO Sitemap 404 Error

Having been downloaded over 1 million times, WordPress SEO by Yoast plugin is by far the best and most complete SEO plugin for WordPress. While it has given us no issues in the past, for some users it has been a pain. Recently one of our clients ran into the issue of getting a 404 error for their sitemaps generated by Yoast’s WordPress SEO plugin. After trying a few things, we were able to figure out the solution. In this article, we will show you how to fix the sitemap 404 error in WordPress SEO plugin by Yoast.

Update: It is important that you understand that this issue is most likely caused by poorly coded theme function or plugin. Yoast’s plugin works fine on our sites. Just wanted to be very clear about this.

First thing you should try is open your .htaccess file (you can actually do this from WordPress SEO plugin > Edit Files option) and simply add the following code in there:

# WordPress SEO - XML Sitemap Rewrite Fix
<IfModule mod_rewrite.c>
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]
# END WordPress SEO - XML Sitemap Rewrite Fix

For most people this fixed the issue. Someone reported that while this code fixed the issue, the page was still sending the 404 response header which meant that Google Webmasters tool couldn’t find it. Well in our client’s case, the above solution did NOT fix the issue.

While not preferred, we had no choice but to edit the core plugin files to fix the issue. As suggested by hadjedj.vincent, we edited the class-sitemaps.php located in “/wp-content/plugins/wordpress-seo/inc/class-sitemaps.php”.

You need to look at the function init() code and make that section look like this:

	 * Initialize sitemaps. Add sitemap rewrite rules and query var
	function init() {
		global $wp_rewrite;
		$GLOBALS['wp']->add_query_var( 'sitemap' );
		$GLOBALS['wp']->add_query_var( 'sitemap_n' );
		add_rewrite_rule( 'sitemap_index.xml$', 'index.php?sitemap=1', 'top' );
		add_rewrite_rule( '([^/]+?)-sitemap([0-9]+)?.xml$', 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'top' );

Basically what we are doing is adding the global $wp_rewrite; before everything that is already there and adding flush_rules after the code. By adding this in the plugin, it seems to fix the 404 issue on our client’s website. We have no idea why Yoast is not doing this by default, but it seems that quite a few users are having this sitemap 404 issue. This issue is explained in the comments.

Update: As some of our users reported that after applying the above fix, they still needed to uncheck the sitemap option in the Yoast’s SEO plugin and save their settings. After that re-checking the sitemap’s option fixed the error for them.

If you were looking for this issue, we hope that this fix has helped you.

Editorial Staff at WPBeginner is a team of WordPress lovers led by Syed Balkhi. Page maintained by Syed Balkhi.

WPBeginner's Video Icon
Our HD-Quality tutorial videos for WordPress Beginners will teach you how to use WordPress to create and manage your own website in about an hour. Get started now »


  1. Matt Klein says:

    There is no function init area in my class-sitemaps.php file. Could it be called something else. What line is it on?

  2. Regina Falkowski says:

    Added the code to .htaccess file and it worked like a charm! Thanks for the fix :)

  3. Alec Byrne says:

    Adding the .htaccess worked for me – thanks very much :-)

  4. Desainwebs says:

    Still not work for me

  5. Ollie says:

    Htaccess fix worked for me.

    But as Scott in the first comment above says, I needed to uncheck the XML sitemap checkbox and save. Then recheck it and save again for the sitemap to show up. I think that would be worth mentioning in the article.

  6. Steve Patterson says:

    Thanks this worked for me editing the .htaccess file. I unchecked sitemaps off then back on and also changed mine from 1,000 to 400. If you are on a shared server, I would use a lower number so that less CPU usage is done on your domain.

  7. scott says:

    Hi guys,

    I had to troubleshoot this issue too. My site is hosted in a sub directory of a main site. So I had to set the following line:

    RewriteBase /scottmortiz/

    I then had to uncheck the mina Site Map XML option in the plugin, and save. Then re-check the plugin and save. Hope this works for some of you.


  8. Chris says:

    Hi Steven,
    thank alot. This helped me, too. But to get the rewrite working I had to disable the xml function, save it, and enable (and save it) again. Seems obvious, but maybe this is worth a note in the article. I will safe this article in my personal wordpress help register.

    • Dan says:

      Thank you Chris! This fixed my 404 problem with Yoast’s XML Sitemap feature.

    • Jason Judge says:

      Ah, switch it off, then switch it back on again. Thanks:-) It is not as obvious as you think. My sitemaps also did not work (getting a 404) until I did this. I did not have to make any of the other changes described in this post.

  9. Shanthi Ganesan says:

    @PEKKO Hi Tried your techniques it really works well,thanks a lot for sharing….

  10. Lukas says:

    Nothing is working in my case – still Error 404 …

  11. Ryan says:

    Beauty, fixed it for me too.. thanks for putting this up

  12. lloyd says:

    this just broke my websites … now getting an internal server error…

  13. Rosie says:

    The edit to .htaccess files was just the trick. Thanks for posting this! You saved me a whole lot of time and trouble.

  14. Pekko says:

    I was just facing the same issue. i unticked the box (Check this box to enable XML sitemap functionality) — pressed save, and then ticked the box again, after that It found the sitemap again, Hope it will be there!

  15. Hugo says:


    I’m still having some troubles with my website:
    My site map contains a lot of files like this one:
    and they refer to a broken link. How can I delete them?

  16. Steven says:

    I’ll just share what worked for me, by changing the ‘max entries per site map’ to 250 (ie. something less than 1000) I managed to fix the 404 error. I think the server was having issues processing 1000 entries which is the default.

    • Maggie says:

      Hi Steven, this is great solution! I just fixed the problem by your method. Thank you very much!

    • PromInc says:

      Thanks Steven – this resolved my issue as well. The ‘max entries…’ field was blank for me; simply adding any value seemed to work, which is good as I felt 250 was a bit low. Very simple but effective solution.

    • Nick Root says:

      That worked thanks for the tip!

Add a Comment

We're glad you have chosen to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and all links are nofollow. Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.