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
Special WordPress Hosting offer for WPBeginner Readers
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 experts 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. Brandon Still says:

    This worked for me, thank you!!!

  2. Nik says:

    Thanks! I was having the hardest time getting it to work and the first section with the .htaccess code did the trick!

  3. Andy Johnston says:

    Worked for me. Thank you!

  4. Kunal Sarkar says:

    Hi all,

    I was facing the same problem while I came across this blog post. But I guess I found a better solution for non-tech guys.

    You can simply install JetPack from WordPress and Activate its Sitemap functionality and disable the Sitemap of Yoast. Additionally Jetpack has a lot of essential features that I guess every WP admin should have.

    Kunal Sarkar

  5. Shivam says:

    For me there is a different issue. Its just showing plain text instead of links. Can some one help please

  6. Naman Kumar says:

    Hey, I’m using the same code goy fixing yoast xml sitemap but what to do for google analytics by yoast?

  7. Mohammed Jhosawa says:

    Hi Guys,

    Please follow this steps if you are facing 404 error issue with Yoast XML Sitemap :

    1. Go to > Yoast SEO Plugin.
    2. Yoast SEO Plugin > XML Sitemap.
    3. Uncheck the user XML Sitemap functionality > Save Changes.
    4. Again Check XML Sitemap functionality > Save Changes.
    5. Click on XML Sitemap and you’ll see your sitemap_index.xml right there.

    Hope this information is useful to you.


  8. Felix says:

    Yo here is an easy way to fix it and should work fine for all!

    Go to settings in wordpress

    Select permalinks

    Don’t change anything

    Just Press save changes at the bottom of the page

    Now click on your XML Site Map button again in Yoast

    404 error should no longer show

    You welcome homies

  9. Deborah says:

    Thank you so much! Worked like a charm to reduce the number from 1000 to 100.

  10. Tim says:

    Simply untick “Check this box to enable XML sitemap functionality.” in the SEO plug-in and Save Changes, then renable again. Problem solved.

  11. Arshad says:

    Thanks Joshua
    Had the same problem. Changing the rows from 1000 to 100 will fixed it for me.

  12. Miro says:

    After adding the first code to your htacces file disable sitemap functionality flush your cache (if you use any of caching tools like w3 total cache) and then enable the functionality again.
    It worked for me that way.

    Thank you for the tutorial! It helped!

  13. aaron says:

    I seem to be getting this for my posts. I suspect yoast is deleting my .htaccess file.

  14. Jeremy Vandermeer says:

    Unchecking and rechecking the XML SItemap option also worked for me. Thanks!

  15. Esteban says:

    Thank you!

  16. Joe says:

    Hey guys. I fixed it! I turned this sitemap option off in this flawless plugin and used a different plugin. It was that easy. It was probably my crummy theme though. Probably.

  17. Atanas Tanev says:

    Ok guys. I was struggling with this issus for a day or so and finally I found the solution!

    Skip the mentioned plugins and the codes which may harm your website. I’ve tried everything!

    Simply uncheck the “remove strip” from yoast plugin and instead of this option just download and install the plugin: “Remove Category URL” from wordpress plugin section.

    The plugin supports WPML and sitemaps and the 404 error is fixed!

    Now you can buy me a beer for saving all your headaches!


    Atanas Tanev

    • Nirav Dave says:

      Hey ATANAS!

      No way man! This solution worked for me mate. Thank you so much for sharing this.


  18. Bas says:

    i placed the code in my .htaccess file and saved it. Now every page gives a 500 internal server Error!!!
    What can i do?

    • Jay says:

      Same with me!!!? Have you managed to fix this?

    • Miles O'Brien says:

      What I did was I went to the xml sitemap page under the SEO plugin and under user sitemap I unchecked disable user sitemap. then when I put in the sitemap into webmasters it worked successfully. I can’t help you with your 500 internal error, But if you do this fresh it should work instead of using the code.

    • Rafael says:

      BAS: Remove the code you entered into your.htaccess file, resave it to the server and reload the website.

  19. Henry says:

    If anyone is using iThemes security plug in and has set it to guard the .htaccess file, disable it and create your sitemap, then re-enable.

  20. Rami Alloush says:

    Uncheck then re-check indeed solved that for me.

  21. Nikos Kavvadas says:

    I add the code in the .htaccess and then i uncheck the sitemap option in the Yoast’s SEO plugin and save their settings. After that i re-checking the sitemap’s option and the the error is solved!


  22. Henk Valk says:

    Thanks Joshua
    Had the same problem. Changing the rows from 1000 to 100 will fixed it for me.

  23. Morteza says:

    Thanks a lot, but not works for me. I do all of these ways and check/save/uncheck/save/XML Sitemap process after one & both of them… but ERROR 404!
    I’ll try another plugins for this.
    thanks for your great site..

  24. Gaurav k says:

    yeah this one is a great finding thanks a lot

  25. TimValDen says:

    Worked for me too… I had the 404page problem when loading the sitemap generated by Yoast SEO.

  26. Joshua Largent says:

    This is what worked for me – Go to the yoast XML sitemap on your dashboard. Change the Max Entries per sitemap from 1000 to 100. Worked like a charm for me. :)

    • Tony says:

      Easy does it again, change from 1000 to 100 did the job, without changing the code. Thank You!

  27. onarto says:

    It looks like htaccess edition disappear since yesterday… nothing in the menu anymore…

  28. Adrienne McCue says:

    Just checking and unchecking takes care of the issue. I will check this plugin out now! I did so much seo before, but I like so many features here!

  29. David Bell says:

    I found the same thing as Jane below. Thank you!

  30. smaug says:

    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)

  31. Awais says:

    i have photography website . Should i uncheck the exclude media option or it’s ok?

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.