The Problem: After setting up Yoast WordPress SEO sitemap, and clicking the link for it you get the dreaded Yoast Sitemap 404 error!
Fix Yoast Sitemap 404 error with these snippets.
While this issue has never been a problem for me in the past, for some users it has been a real pain. Recently several of my 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, I was able to figure out the solution. In this article, I am going to show you how to fix the Yoast sitemap 404 error in right in the WordPress SEO plugin by Yoast. There’s a seperate fix if you’re using W3 Total Cache and have the same problem.
It is important that you understand that this issue is most likely caused by poorly coded theme function or another plugin. But it’s easy enough to fix. Yoast’s plugin works fine on my sites. I use custom coded themes and plugins.
First be certain you have no conflicting plugins (any plugin that might generate an xml sitemap). If you have one, disable and delete it.
Then you should open your .htaccess file (you can actually do this from WordPress SEO plugin / Edit Files option) and simply add the following code in there:
[pastacode lang=”markup” message=”” highlight=”” provider=”manual” manual=”%23%20WordPress%20SEO%20-%20Sitemap%20Rewrite%20Fix%0A%3CIfModule%20mod_rewrite.c%3E%0ARewriteEngine%20On%0ARewriteBase%20%2F%0ARewriteRule%20%5Esitemap_index.xml%24%20%2Findex.php%3Fsitemap%3D1%20%5BL%5D%0ARewriteRule%20%5E(%5B%5E%2F%5D%2B%3F)-sitemap(%5B0-9%5D%2B)%3F.xml%24%20%2Findex.php%3Fsitemap%3D%241%26sitemap_n%3D%242%20%5BL%5D%0A%3C%2FIfModule%3E%0A%23%20END%20WordPress%20SEO%20-%20Sitemap%20Rewrite%20Fix”/]
Save and then go to WordPress Settings/Permalinks and re-save your permalink structure. You should be able to see your sitemap index when you click You can find your XML Sitemap here. When you submit your sitemap to google INSERT only the portion of the url that is /sitemap_index.xml. (BE SURE YOU REMOVE THE PERIOD)
If you have W3 Total Cache active, that is preventing 404 errors for static files to go through to WordPress. Update to the latest version of W3 Total Cache or add, under the browser cache page, this exemption:
[pastacode lang=”markup” message=”credit: Yoast” highlight=”” provider=”manual” manual=”sitemap(_index%7C%5B0-9%5D%2B)%3F.xml”/]
Save and then go to WordPress Settings/Permalinks and re-save your permalink structure. You should be able to see your sitemap index when you click You can find your XML Sitemap here. When you submit your sitemap to google INSERT only the portion of the url that is /sitemap_index.xml. (BE SURE YOU REMOVE THE PERIOD)
Does working inside your WordPress installation ‘freak’ you out? Totally afraid you’ll blow your site out of the water? Fear Not! We can help, just visit our Project Inquiry and we’ll get you taken care of in a blink of the eye.
JO says
Hi,
Very new at this! Have managed to generate the sitemap through Yoast and submitted to Google Webmaster. 3 of the 4 sitemaps were recognised almost immediately but one (posts- the most important one!)- is still pending with the dreaded 404 error message. I’ve updated to W3Cache Total, and resaved permalinks, I’ve also disabled sitemaps and re-saved…still error message and pending.
I saw on the Yoast blog that this sometimes happens if you have no content in that category, but I have numerous posts, so I am in a puzzle…
Any advice? Not at all familiar with code, so please be gentle and explain like you are talking to a 2 year old.
Many thanks,
Jo
Debbie says
disable your caching and resubmit the entire sitemap
Mark S. says
Thank you very very much Debbie!
It worked well with Yoast and finally I could get my pages properly indexed (alongside with other Google recommended techniques).
Best thoughts!
Debbie says
glad you got it sorted!