WPBeginner

Beginner's Guide for WordPress

  • Blog
    • Beginners Guide
    • News
    • Opinion
    • Showcase
    • Themes
    • Tutorials
    • WordPress Plugins
  • Start Here
    • How to Start a Blog
    • Create a Website
    • Start an Online Store
    • Best Website Builder
    • Email Marketing
    • WordPress Hosting
  • Deals
    • Bluehost Coupon
    • SiteGround Coupon
    • WP Engine Coupon
    • HostGator Coupon
    • Domain.com Coupon
    • Constant Contact
    • View All Deals »
  • Glossary
  • Videos
  • Products
X
☰
Beginner's Guide for WordPress / Start your WordPress Blog in minutes
Choosing the Best
WordPress Hosting
How to Easily
Install WordPress
Recommended
WordPress Plugins
View all Guides

WPBeginner» Blog» Tutorials» How to Fix Yoast’s WordPress SEO Sitemap 404 Error

How to Fix Yoast’s WordPress SEO Sitemap 404 Error

Last updated on April 13th, 2014 by Editorial Staff
61 Shares
Share
Tweet
Share
Pin
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]
</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.

61 Shares
Share
Tweet
Share
Pin
Popular on WPBeginner Right Now!
  • Checklist

    Checklist: 15 Things You MUST DO Before Changing WordPress Themes

  • Revealed: Why Building an Email List is so Important Today (6 Reasons)

    Revealed: Why Building an Email List is so Important Today (6 Reasons)

  • How to Properly Move Your Blog from WordPress.com to WordPress.org

  • Error Establishing a Database Connection in WordPress

    How to Fix the Error Establishing a Database Connection in WordPress

About the Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi. Trusted by over 1.3 million readers worldwide.

The Ultimate WordPress Toolkit

231 Comments

Leave a Reply
  1. Binod Raj Joshi says:
    Mar 2, 2019 at 9:03 am

    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!

    Reply
    • WPBeginner Support says:
      Mar 4, 2019 at 10:51 am

      You’re welcome, glad our guide could help :)

      Reply
  2. saurab says:
    Dec 4, 2018 at 9:21 am

    Hi
    After moving to https from http, Sitemap address is displaying 404 error, Is it possible know the solution for this ?

    Reply
  3. Ashish Sharma says:
    Aug 1, 2018 at 11:23 pm

    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

    Reply
  4. RAJEEV KUMAR says:
    Jun 7, 2018 at 7:48 am

    Sir, In my WordPress blog, 410 Response code error are showing in Yoast SEO’S Search Console feature. How I fix It.

    Reply
  5. seerity says:
    Dec 2, 2017 at 3:30 pm

    Thanks, this fixed mine.

    Reply
  6. Tracy Pope says:
    Nov 5, 2017 at 6:34 pm

    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??

    Reply
    • WPBeginner Support says:
      Nov 6, 2017 at 4:04 pm

      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.

      Reply
  7. Amit says:
    Aug 19, 2017 at 10:03 am

    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.

    Reply
    • WPBeginner Support says:
      Aug 20, 2017 at 8:33 am

      Hi Amit,

      Keep the existing code and paste the new code below it.

      Reply
  8. Keitai says:
    Jul 13, 2017 at 5:42 pm

    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?

    Reply
  9. Carol says:
    Jun 28, 2017 at 2:27 pm

    I did the first option and now I have an internal server error!

    Reply
  10. Tony says:
    Jun 16, 2017 at 9:25 am

    Thanks for listening. I got the solution cheers

    Reply
    • WPBeginner Support says:
      Jun 16, 2017 at 10:42 pm

      Hey Tony,

      Glad to hear that you found a solution. Good luck :)

      Reply
  11. Tony says:
    Jun 16, 2017 at 8:50 am

    @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

    Reply
  12. Tony says:
    Jun 15, 2017 at 4:38 pm

    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

    Reply
    • WPBeginner Support says:
      Jun 15, 2017 at 11:55 pm

      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.

      Reply
  13. nageswarao says:
    Dec 29, 2016 at 4:51 am

    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

    Reply
  14. Brandon Still says:
    Sep 4, 2016 at 4:15 am

    This worked for me, thank you!!!

    Reply
  15. Nik says:
    May 6, 2016 at 1:20 am

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

    Reply
  16. Andy Johnston says:
    Apr 11, 2016 at 4:58 pm

    Worked for me. Thank you!

    Reply
  17. Kunal Sarkar says:
    Mar 26, 2016 at 12:57 am

    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

    Reply
  18. Shivam says:
    Feb 4, 2016 at 2:33 am

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

    Reply
  19. Naman Kumar says:
    Jan 12, 2016 at 10:58 pm

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

    Reply
  20. Mohammed Jhosawa says:
    Jan 11, 2016 at 12:05 am

    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.

    Reply
    • Alx Diesel says:
      Mar 11, 2016 at 1:34 pm

      @Mohammed Your suggestion worked. Thanks a lot.

      Reply
    • Amar says:
      Apr 15, 2016 at 7:41 am

      Thnks bro this worked for me.

      Reply
    • Mr. Dif says:
      Sep 16, 2016 at 1:40 pm

      This worked for me also although I did implement the .htacess change as well.

      Reply
    • Mohammed says:
      Oct 7, 2016 at 11:54 am

      Your idea was good and thanks a lot

      Reply
    • Faisal Sofi says:
      Jan 15, 2017 at 12:30 am

      It worked… Thanks

      Reply
  21. Felix says:
    Jan 7, 2016 at 10:06 pm

    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

    Reply
    • Pankaj says:
      Feb 26, 2016 at 1:52 am

      Yah This is fixed! Thanks a lot!

      Reply
    • Christian says:
      Aug 3, 2016 at 11:42 am

      thanks man, this worked.

      Reply
    • Grant says:
      Aug 5, 2016 at 12:30 pm

      Reply to say that this method worked for me. Just go to permalinks page in settings, and click save.

      Reply
    • Raf says:
      Sep 9, 2016 at 11:43 am

      Awesome!! It worked.

      Reply
    • Sergey says:
      Jul 15, 2017 at 2:18 pm

      Thanx! fixed for me

      Reply
  22. Deborah says:
    Dec 22, 2015 at 5:16 pm

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

    Reply
  23. Tim says:
    Dec 5, 2015 at 6:52 pm

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

    Reply
  24. Arshad says:
    Oct 2, 2015 at 12:36 pm

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

    Reply
    • Klick says:
      Nov 4, 2015 at 8:59 am

      Thx i have change it too from 1000 to 100 now it work Thanx

      Reply
    • Ridfay says:
      May 19, 2016 at 2:21 am

      Now work with this tips thanx

      Reply
  25. Miro says:
    Sep 20, 2015 at 3:51 pm

    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!

    Reply
  26. aaron says:
    Sep 13, 2015 at 6:53 am

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

    Reply
  27. Jeremy Vandermeer says:
    Sep 4, 2015 at 12:19 pm

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

    Reply
  28. Esteban says:
    Aug 26, 2015 at 5:22 pm

    Thank you!

    Reply
  29. Joe says:
    Aug 18, 2015 at 12:06 pm

    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.

    Reply
  30. Atanas Tanev says:
    Aug 2, 2015 at 7:25 am

    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

    Reply
    • Nirav Dave says:
      Aug 14, 2015 at 7:24 am

      Hey ATANAS!

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

      Nirav

      Reply
  31. Bas says:
    Jul 17, 2015 at 2:08 pm

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

    Reply
    • Jay says:
      Jul 21, 2015 at 5:37 am

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

      Reply
    • Miles O'Brien says:
      Nov 15, 2015 at 10:45 am

      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.

      Reply
    • Rafael says:
      Nov 16, 2015 at 2:48 pm

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

      Reply
  32. Henry says:
    Jul 2, 2015 at 12:40 pm

    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.

    Reply
  33. Rami Alloush says:
    May 24, 2015 at 8:30 am

    Uncheck then re-check indeed solved that for me.
    Thanks

    Reply
    • Chris says:
      Aug 1, 2015 at 3:27 am

      LOL This worked for me too. I looked at 25 pages before I saw your comment.

      Reply
  34. Nikos Kavvadas says:
    May 20, 2015 at 7:08 am

    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!

    Reply
  35. Henk Valk says:
    Apr 29, 2015 at 4:04 am

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

    Reply
  36. Morteza says:
    Mar 13, 2015 at 10:08 am

    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..

    Reply
  37. Gaurav k says:
    Mar 8, 2015 at 9:53 am

    yeah this one is a great finding thanks a lot

    Reply
  38. TimValDen says:
    Jan 15, 2015 at 4:19 pm

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

    Reply
  39. Joshua Largent says:
    Dec 30, 2014 at 3:38 pm

    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. :)

    Reply
    • Tony says:
      Nov 9, 2015 at 6:18 am

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

      Reply
  40. onarto says:
    Nov 20, 2014 at 7:35 pm

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

    Reply
  41. Adrienne McCue says:
    Oct 23, 2014 at 11:38 pm

    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!

    Reply
  42. David Bell says:
    Sep 24, 2014 at 10:19 pm

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

    Reply
  43. smaug says:
    Sep 23, 2014 at 5:26 pm

    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)

    Reply
  44. Awais says:
    Sep 19, 2014 at 11:25 am

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

    Reply
  45. CB says:
    Sep 2, 2014 at 3:00 pm

    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.

    Reply
  46. Matt Crystal says:
    Sep 1, 2014 at 10:38 am

    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!

    Reply
  47. Roderick van Straten says:
    Aug 27, 2014 at 7:36 am

    Added this code to the .htaccess and unchecked and checked it, but I only get a blank page now for the sitemap ..

    Reply
  48. mandingo345 says:
    Aug 8, 2014 at 11:33 am

    yes, without fix, just uncheck save recheck and saved.

    Reply
  49. Tidus Ha says:
    Jul 24, 2014 at 11:28 pm

    the last update work perfect for me. thank you.

    Reply
  50. Jack says:
    Jul 21, 2014 at 11:50 am

    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!

    Reply
« 1 2 3

Leave a Reply Cancel reply

Thanks for choosing to leave a comment. Please keep in mind that all comments are moderated according to our comment policy, and your email address will NOT be published. Please Do NOT use keywords in the name field. Let's have a personal and meaningful conversation.

Over 1,320,000+ Readers

Get fresh content from WPBeginner

Featured WordPress Plugin
SeedProd WordPress Coming Soon Page Plugin
SeedProd
Jump start your website with viral coming soon pages. Learn More »
How to Start a Blog How to Start a Blog
I need help with ...
Starting a
Blog
WordPress
Performance
WordPress
Security
WordPress
SEO
WordPress
Errors
Building an
Online Store
Useful WordPress Guides
    • 7 Best WordPress Backup Plugins Compared (Pros and Cons)
    • How to Fix the Error Establishing a Database Connection in WordPress
    • Why You Need a CDN for your WordPress Blog? [Infographic]
    • 25 Legit Ways to Make Money Online Blogging with WordPress
    • Self Hosted WordPress.org vs. Free WordPress.com [Infograph]
    • Free Recording: WordPress Workshop for Beginners
    • 24 Must Have WordPress Plugins for Business Websites
    • How to Properly Move Your Blog from WordPress.com to WordPress.org
    • 5 Best Contact Form Plugins for WordPress Compared
    • Which is the Best WordPress Popup Plugin? (Comparison)
    • Best WooCommerce Hosting in 2019 (Comparison)
    • How to Fix the Internal Server Error in WordPress
    • How to Install WordPress - Complete WordPress Installation Tutorial
    • Why You Should Start Building an Email List Right Away
    • How to Properly Move WordPress to a New Domain Without Losing SEO
    • How to Choose the Best WordPress Hosting for Your Website
    • How to Choose the Best Blogging Platform (Comparison)
    • WordPress Tutorials - 200+ Step by Step WordPress Tutorials
    • 5 Best WordPress Ecommerce Plugins Compared
    • 5 Best WordPress Membership Plugins (Compared)
    • 7 Best Email Marketing Services for Small Business (2019)
    • How to Choose the Best Domain Registrar (Compared)
    • The Truth About Shared WordPress Web Hosting
    • When Do You Really Need Managed WordPress Hosting?
    • 5 Best Drag and Drop WordPress Page Builders Compared
    • How to Switch from Blogger to WordPress without Losing Google Rankings
    • How to Properly Switch From Wix to WordPress (Step by Step)
    • How to Properly Move from Weebly to WordPress (Step by Step)
    • Do You Really Need a VPS? Best WordPress VPS Hosting Compared
    • How to Properly Move from Squarespace to WordPress
    • How to Register a Domain Name (+ tip to get it for FREE)
    • HostGator Review - An Honest Look at Speed & Uptime (2019)
    • SiteGround Reviews from 1032 Users & Our Experts (2019)
    • Bluehost Review from Real Users + Performance Stats (2019)
    • How Much Does It Really Cost to Build a WordPress Website?
    • How to Create an Email Newsletter the RIGHT WAY (Step by Step)
    • 7 Best CRM Software for Small Businesses (Compared)
    • How to Create a Free Business Email Address in 5 Minutes (Step by Step)
    • How to Install Google Analytics in WordPress for Beginners
    • How to Move WordPress to a New Host or Server With No Downtime
    • Why is WordPress Free? What are the Costs? What is the Catch?
    • How to Make a Website in 2019 – Step by Step Guide
Deals & Coupons (view all)
Weglot Coupon
Get 15% OFF on Weglot multilingual plugin for WordPress.
Webnus
Webnus Coupon
Get 20% OFF on Webnus themes and plugins for WordPress.
Featured In
About WPBeginner®

WPBeginner is a free WordPress resource site for Beginners. WPBeginner was founded in July 2009 by Syed Balkhi. The main goal of this site is to provide quality tips, tricks, hacks, and other WordPress resources that allows WordPress beginners to improve their site(s).

Site Links
  • About Us
  • Contact Us
  • FTC Disclosure
  • Privacy Policy
  • Terms of Service
  • Free Blog Setup
Our Sites
  • OptinMonster
  • MonsterInsights
  • WPForms
  • SeedProd
  • Nameboy
  • RafflePress

Copyright © 2009 - 2019 WPBeginner LLC. All Rights Reserved. WPBeginner® is a registered trademark.

Managed by Awesome Motive | WordPress hosting by HostGator | WordPress CDN by MaxCDN | WordPress Security by Sucuri.