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] </IfModule> # 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' ); $wp_rewrite->flush_rules(); }
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.
Hey, wpbeginner, I was in sitemap trouble from a few days, now it have been solved. Learning a lot from you guys about wp error fixing, thanks!
You’re welcome, glad our guide could help
Hi
After moving to https from http, Sitemap address is displaying 404 error, Is it possible know the solution for this ?
Nice pluging , but when I am creating sitmap using yoast and submitting it to webmaster it is showing 404 error for multiple urls. I searched in my site no where those urls exist. But y these are coming into sitemap I don’t understand any expert to help me
Sir, In my WordPress blog, 410 Response code error are showing in Yoast SEO’S Search Console feature. How I fix It.
Thanks, this fixed mine.
I tried to download the Yoast SEO plug in and I received this error message:
Fatal error: Call to undefined function apply_filters_deprecated() in /websites/websitename/wp-content/plugins/wordpress-seo/admin/menu/class-admin-menu.php on line 246
I now can’t get into my back end of the website at all I just keep getting this error? What can I do??
Hi Tracy,
You need to connect to your website using FTP or File Manager app in your cPanel account. Go to wp-content/plugins/ and delete wordpress-seo folder. After that you will be able to login to your WordPress admin area and reinstall the plugin.
Hi,
To edit the .htaccess file do we need to remove the existing code and add your code
or
keep the existing code and add your code also?
Need help.
Hi Amit,
Keep the existing code and paste the new code below it.
hmm,
Tried every suggestion but still got a 404. somehow i can’t redirect xml html htm php file extensions.
when i try
RewriteRule ^sitemap_index.xl$ /site/index.php?sitemap=1 [L] and not
RewriteRule ^sitemap_index.xml$ /site/index.php?sitemap=1 [L]
Hence, i removed the “m”, and the redirect works but sitemap_index.xml doesn’t
Any more tips?
I did the first option and now I have an internal server error!
Thanks for listening. I got the solution cheers
Hey Tony,
Glad to hear that you found a solution. Good luck
@wpbeginner support. I have already gotten the sitemap, the issue when I submit it to google for test it bring out an error http 404. I have read your post on how to edit .ht access file and wp seo. I have also check and unchecked the yoast plugin. But it hasn’t resolved the http 404. Please help
i just opened a new WordPress site. I have tried everything still the site app generated by yoast seo is still showing http 404 error. What do I do. The website is . please note I have edited my .htaccess file, edited wp-content/Wordpress. Pap, unchecked and checked site map settings for seo, saved permalinks. I even used a free sitemap generator upload the file via my Cpanel but still am getting the same error
Hi Tony,
If you are unable to find Yoast SEO generated sitemap file, then it is located at http://example.com/sitemap_index.xml
Replace example.com with your own domain name.
hi bro my website Google XML Sitemaps not showing last 5 months (sitemap-pt-post-2016-06.xml end after not showing) and also sitemap-tax-post_tag.xml not showing how to solve my problem
This worked for me, thank you!!!
Thanks! I was having the hardest time getting it to work and the first section with the .htaccess code did the trick!
Worked for me. Thank you!
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.
Thanks,
Kunal Sarkar
For me there is a different issue. Its just showing plain text instead of links. Can some one help please
Hey, I’m using the same code goy fixing yoast xml sitemap but what to do for google analytics by yoast?
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.
Thanks.
@Mohammed Your suggestion worked. Thanks a lot.
Thnks bro this worked for me.
This worked for me also although I did implement the .htacess change as well.
Your idea was good and thanks a lot
It worked… Thanks
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
Yah This is fixed! Thanks a lot!
thanks man, this worked.
Reply to say that this method worked for me. Just go to permalinks page in settings, and click save.
Awesome!! It worked.
Thanx! fixed for me
Thank you so much! Worked like a charm to reduce the number from 1000 to 100.
Simply untick “Check this box to enable XML sitemap functionality.” in the SEO plug-in and Save Changes, then renable again. Problem solved.
Thanks Joshua
Had the same problem. Changing the rows from 1000 to 100 will fixed it for me.
Thx i have change it too from 1000 to 100 now it work Thanx
Now work with this tips thanx
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!
I seem to be getting this for my posts. I suspect yoast is deleting my .htaccess file.
Unchecking and rechecking the XML SItemap option also worked for me. Thanks!
Thank you!
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.
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!
Cheers!
Atanas Tanev
Hey ATANAS!
No way man! This solution worked for me mate. Thank you so much for sharing this.
Nirav
i placed the code in my .htaccess file and saved it. Now every page gives a 500 internal server Error!!!
What can i do?
Same with me!!!? Have you managed to fix this?
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.
BAS: Remove the code you entered into your.htaccess file, resave it to the server and reload the website.
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.
Uncheck then re-check indeed solved that for me.
Thanks
LOL This worked for me too. I looked at 25 pages before I saw your comment.
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!
Thanks!
Thanks Joshua
Had the same problem. Changing the rows from 1000 to 100 will fixed it for me.
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..
yeah this one is a great finding thanks a lot
Worked for me too… I had the 404page problem when loading the sitemap generated by Yoast SEO.
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.
Easy does it again, change from 1000 to 100 did the job, without changing the code. Thank You!
It looks like htaccess edition disappear since yesterday… nothing in the menu anymore…
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!
I found the same thing as Jane below. Thank you!
adding the following code to my .htaccess fixed the sitemap for me:
https://gist.github.com/jdevalk/5345872
(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)
i have photography website . Should i uncheck the exclude media option or it’s ok?
Hi, just tried the second version editing the plug ins core files and the site has disapeared?? including the backend. just a white screen?? I replaced the code withy the original and nothing.
Thank you! That worked by supplying the code in the .htaccess file, then unchecking the site map option and saving. Then, re-checking the box and saving again. Thanks!
Added this code to the .htaccess and unchecked and checked it, but I only get a blank page now for the sitemap ..
yes, without fix, just uncheck save recheck and saved.
the last update work perfect for me. thank you.
After loosing quite some time trying to find what was wrong, I got it working by your suggestion “Uncheck the sitemap option in the Yoast’s SEO plugin and ‘save’ settings. After that re-checking the sitemap’s option fixes the error.”
tnx very much!