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
Follow WPBeginner on YouTube
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 »
  • smaug

    adding the following code to my .htaccess fixed the sitemap for me:

    (note this code is for if your wordpress installation is in a subdirectory named wordpress, if your is in a different folder, change the directory name in the code)

  • johnny

    Thank you so much! unchecking, saving, rechecking saving did the trick!

  • alireza

    it work for me too, Thanks a lot!

  • Elle Laurel Rose

    Woohoo! Thanks. Mine probably wasn’t broken long because Google didn’t seem to mind yet. … But my site is only in a softer launch stage anyway… Slow crawls maybe. Luckily, I’m improving my site before my real projects go up (hopefully soon).

    Anyway I cannot thank you enough. :)

  • Basie

    Editing the .htaccess file, un-checking sitemap generation, saving settings, re-checking, saving settings … fixed it for me! Thank you VERY much.

  • Fernando

    Were you able to fix this one? I’m having the same problem, I get a 404 on post-sitemap.xml. I didn’t check the PHP logs on what the error is but probably would be the same you’re getting.

  • hayderabbass

    Disabling the XML sitemap and re enabling them fix this issue for me. Thanks!

  • Katrina Isabelle

    Try going into your permalink settings and saving them again. If you can’t access the back end of your site because of the 500 error, then remove that htaccess file.

  • Katrina Isabelle

    Hello! I think you should add one more step at the very beginning: Re-save your permalink settings! I found that re-saving my permalink settings solved the issue for me. No need to go into the htaccess file.

  • Tiffany Marie McAnally

    So it still doesn’t work for me… I feel like beating my head against a wall. As much as I love the plugin, I think I’m just going to lose it in favor of something that’s actually functional.

  • Matt Klein

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

  • Regina Falkowski

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

  • Alec Byrne

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

  • Desainwebs

    Still not work for me

  • Ollie

    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.

    • WPBeginner Support

      Ollie, yes we have updated the article.

  • Steve Patterson

    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.

  • scott

    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.


  • Chris

    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

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

    • Jason Judge

      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.

  • Shanthi Ganesan

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

  • Lukas

    Nothing is working in my case – still Error 404 …

  • Ryan

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

  • lloyd

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

  • Rosie

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

  • Pekko

    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!

    • Anisa

      I use this technique, and it worked

    • John

      This worked for me, as well. Thx!

    • Cara Sherlock

      Unchecking, saving and then rechecking worked for me too. Thx!

    • Badprimer

      [..unticked the box (Check this box to enable XML sitemap functionality) — pressed save, and then ticked the box again..]

      Worked for me. Thx!! :D

    • Kerry

      Thank you! Worked for me too! So simple. The author of this article should add this too.

    • bruce

      This also worked for me. turn off sitemaps. save. turn them back on. save. fixed

    • David

      Same for me, unchecked, saved, checked, saved, voila!

  • Hugo


    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?

    • WPBeginner Support

      Doesn’t look like a broken link.

  • Steven

    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

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

    • PromInc

      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

      That worked thanks for the tip!