Trusted WordPress tutorials, when you need them most.
Beginner’s Guide to WordPress
WPB Cup
25 Million+
Websites using our plugins
16+
Years of WordPress experience
3000+
WordPress tutorials
by experts

How to Fix Yoast’s WordPress SEO Sitemap 404 Error

Dealing with a 404 error on your Yoast SEO sitemap in WordPress can be frustrating. Yoast SEO is a popular tool, but sometimes, a plugin conflict or incorrect settings can cause this error.

So, if you try to visit your XML sitemap and you see a 404 error, it can stop you in your tracks. But don’t worry, there are easy fixes.

At WPBeginner, we’ve encountered and resolved this issue, if not a hundred times. In this article, we’ll guide you step-by-step to fix the Yoast SEO sitemap 404 error. Just follow along to get your sitemap working smoothly again.

Fixing Yoast SEO XML sitemap 404 error in WordPress

What’s Causing Yoast SEO Sitemap 404 Error in WordPress?

The Yoast SEO sitemap helps search engines find all the content on your website that you want them to find and index.

Fixing the error ensures that search engines can access your sitemap and discover all the pages and content on your site. This can lead to better search engine visibility and ranking, and it will also help rank your content faster than without a sitemap.

WordPress has a default XML sitemap that you can submit to Google Search Console and other search engines.

This XML sitemap can be visited by entering the following URL in your browser’s address bar:

https://example.com/sitemap.xml

However, this default WordPress-generated sitemap is very basic. To fix this, all top WordPress SEO plugins like Yoast SEO and the All in One SEO plugin create their own XML sitemaps with more features.

When you use the XML sitemap generated by your WordPress SEO plugin, the plugin rewrites the default WordPress XML sitemap shortcut.

This means that the sitemap URL mentioned above will then send users to the sitemaps generated by your WordPress SEO plugin.

Unfortunately, this may cause a 404 error on some websites due to plugin conflicts or incorrect WordPress settings.

In the following sections, we’ll show you how to easily fix the WordPress sitemap 404 error in the Yoast SEO plugin. Here’s a quick overview of all the methods we’ll cover:

Ready? Let’s jump right in.

WordPress comes with an SEO-friendly URL structure, called permalinks. This URL structure uses a redirect system to tell your web hosting server which page to load when a user enters a URL in their browser.

Normally, these permalinks settings are automatically updated when you make changes to your website.

The bad news is that sometimes WordPress is unable to refresh the permalink structure, which can cause Yoast SEO’s sitemap 404 error to appear.

That said, this can be easily fixed by going to the Settings » Permalinks page from the WordPress admin area and simply clicking on the ‘Save Changes’ button.

Update permalinks

Doing so will refresh the WordPress permalink settings. You can now visit your XML sitemap page to see if this has fixed your problem.

If it didn’t fix the problem, then you can continue reading.

If refreshing your WordPress permalink structure doesn’t fix the 404 error, then you can manually tell your web server to redirect users to Yoast SEO’s sitemap page.

To do this, you’ll need to add the following code to your .htaccess file.

# Yoast SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^locations.kml$ /index.php?sitemap=wpseo_local_kml [L]
RewriteRule ^geo_sitemap.xml$ /index.php?sitemap=geo [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?yoast-sitemap-xsl=$1 [L]
# END Yoast SEO - XML Sitemap Rewrite Fix

Note: If your WordPress website is installed in a subdirectory or folder (e.g. https://example.com/mywebsite/ ), then you’ll need to use the following code.

# Yoast SEO - XML Sitemap Rewrite Fix
RewriteEngine On
RewriteBase /mywebsite/
RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L]
RewriteRule ^locations.kml$ /index.php?sitemap=wpseo_local_kml [L]
RewriteRule ^geo_sitemap.xml$ /index.php?sitemap=geo [L]
RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L]
RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?yoast-sitemap-xsl=$1 [L]
# END Yoast SEO - XML Sitemap Rewrite Fix

Don’t forget to replace /mywebsite/ with your subdirectory name.

This code simply tells your web server which pages to display when users access Yoast SEO’s XML sitemaps.

You can now try viewing your XML sitemap to see if this resolves your issue.

3. Switch to an XML Sitemaps Plugin

If the above-mentioned methods didn’t solve the 404 error on Yoast SEO’s XML sitemap page, then you can try using a separate plugin to generate XML sitemaps for your website. And a good plugin for this is the XML Sitemaps plugin.

The disadvantage of this approach is that you’ll have to rely on a separate plugin to generate XML sitemaps and Yoast SEO for other SEO features.

First, you need to install and activate the XML Sitemaps plugin. For more details, you can see our step-by-step guide on how to install a WordPress plugin.

Since you are using Yoast SEO, you will automatically receive a notification to disable the XML Sitemaps plugin or Yoast SEO’s sitemap functionality.

Yoast SEO XML Sitemap conflict warning

Then, you can click on the ‘Toggle Yoast SEO’s XML Sitemap’ button to continue.

This will bring you to the ‘Features’ tab under SEO » General. From here, you’ll need to scroll down to the ‘XML sitemaps’ option and switch it off.

Disabling XML sitemaps in Yoast SEO

Don’t forget to click on the ‘Save Changes’ button to store your settings.

You can now switch to the Settings » XML-Sitemap page to configure your sitemaps. For most websites, default settings would work out of the box.

XML Sitemaps settings

But you can always configure the settings based on your needs.

You can now submit the XML sitemap URL to the Google search console and other search engines.

Sitemap URL

4. Switch to the All in One SEO for WordPress

If all the above fail and you don’t want to use a separate plugin to generate XML sitemaps, then this method may help you fix the sitemap 404 error issue.

For this method, you’ll need All in One SEO for WordPress. It’s the best WordPress SEO plugin on the market and a much better Yoast SEO alternative.

You can see our Yoast vs All in One SEO comparison for more details on the differences.

All-in-One SEO (AIOSEO) comes with advanced XML sitemaps and easy-to-manage options that give you full control over what to include or exclude from them.

First, let’s install and activate the All in One SEO for WordPress plugin. For more details, see our step-by-step guide on how to install a WordPress plugin.

Note: There is also a free version of All in One SEO for WordPress, which includes most XML sitemap features except for video and news.

Upon activation, the plugin will walk you through a setup wizard. If you need help during setup, follow our guide on how to properly set up the All in One SEO plugin for WordPress.

All in One SEO setup

All in One SEO will also allow you to import SEO data from Yoast SEO.

This ensures that all your previous SEO meta tags and titles remain unchanged.

Import Yoast SEO data

After the initial setup, you can go to All in One SEO » Sitemaps page to configure XML sitemap settings.

You can click the ‘Open Sitemap’ button to see if it fixed the sitemap 404 error in WordPress.

All in One SEO sitemaps settings

After that, you configure sitemap settings if needed.

For instance, All in One SEO allows you to choose what to include in your sitemaps. You can add or remove post types, taxonomies, individual posts, and pages.

All in One SEO sitemaps advanced settings

All in One SEO also allows you to create video, news, RSS sitemap, and HTML sitemap for your website.

Simply explore its tabs to see if you want to configure more settings.

Additional sitemaps settings

These sitemaps can also be submitted to Google Search Console and other search engines. This helps search engines quickly find newer content on your website.

Expert Tip: Don’t want to fix that WordPress error yourself? No worries – we’ve got you covered! Say goodbye to frustrating errors and get back to focusing on what you love. Let us handle the tech stuff, and book our Emergency WordPress Support now!

We hope this article helped you fix the Yoast SEO Sitemap 404 error in WordPress. Next, you may also want to see our complete WordPress troubleshooting guide or see how to fix common WordPress errors.

If you liked this article, then please subscribe to our YouTube Channel for WordPress video tutorials. You can also find us on Twitter and Facebook.

Disclosure: Our content is reader-supported. This means if you click on some of our links, then we may earn a commission. See how WPBeginner is funded, why it matters, and how you can support us. Here's our editorial process.

Editorial Staff

Editorial Staff at WPBeginner is a team of WordPress experts led by Syed Balkhi with over 16 years of experience in WordPress, Web Hosting, eCommerce, SEO, and Marketing. Started in 2009, WPBeginner is now the largest free WordPress resource site in the industry and is often referred to as the Wikipedia for WordPress.

The Ultimate WordPress Toolkit

Get FREE access to our toolkit - a collection of WordPress related products and resources that every professional should have!

Reader Interactions

242 CommentsLeave a Reply

  1. CB

    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.

  2. Matt Crystal

    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!

  3. Roderick van Straten

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

  4. mandingo345

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

  5. Jack

    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!

  6. johnny

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

  7. sc456a

    After I added the code to htaccess and unchecked/rechecked Sitemap in the plugin, it worked! Thanks!

  8. alireza

    it work for me too, Thanks a lot!

  9. Leo

    Uncheck then save, then go back check again and save, solved my problem. It should be at the begining before anybody try anything else! it worked for me thanks though

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

  11. logitaki

    I opened the class-sitemaps.php file but can’t find the section you are referring to “functiion () init code.. can you be more specific?

  12. Basie

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

  13. Tom Atkinson

    I found my issue was actually fixed purely by turning Yoasts sitemaps on and off from UI. Which is great! :)

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

    • Steve

      No fix, and theres no replies to support threads on wordpress, other people are just disabling it and using another sitemap plugin.

  15. hayderabbass

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

  16. Ben Billson

    I was having an issue with the sitemap 404’ing when trying to access it.

    I tried adding the first ifmodule, no joy, then remembered I had another ifmodule in place to handle redirects after updating my permalink structure.

    I removed the redirect ifmodule, restarted Worpress SEO, then the sitemaps started working. Re-added the redirect ifmodule, and everything now appears to be working just fine. I’ve also checked the status in GWT and Bing WT and it’s all looking good. Thanks for the help!

  17. Rob Cooper

    I put the first Ifmodule into htaccess and it spit out some weird single line of content, with no links.

    I read through the comments

    then I rebooted Yoast’s sitemap option:

    i unchecked the “Enable XML Sitemap Here” and saved

    I re-checked it and saved

    checked my sitemap and it was there, formatted properly with xsl stylesheet being applied and links all worked

  18. chiappa

    I have no idea where to put that code. There is no line like: “function init()” in class-sitemaps.php

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

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

    • EB

      Exactly, solved my problem too.

    • Alfonso

      this fixed the issue for me, re-saving the WP permalinks

  21. Steve

    I get the following error only on post-sitemap, all other sitemaps work ok:
    Fatal error: Allowed memory size../plugins/wordpress-seo/inc/class-sitemaps.php on line 713
    I tried the htaccess and wpseo-functions edits but no luck.
    I deactivated every plugin, still no luck.
    I deleted wpseo and reinstalled but still same problem and now on the wpseo dashboard and sitemaps page I get this error:
    Warning: call_user_func_array() expects parameter 1 to be a valid callback, function ‘wpseo_xml_sitemaps_init’ not found or invalid function name in /home/justplay/public_html/wp/wp-includes/plugin.php on line 470

    I have two sites running the same theme, plugins etc and one works ok one has this errors, wierd.

  22. Jane Hockley

    Thank you – i found just by unchecking and saving and then re-checking the site map option for the yoast plugin google webmaster was able to find my site map

    • eliascan

      Worked for me too. Thanks

    • Jared Eitnier

      Worked for me as well, good call.

    • Jesse

      This worked for me too. Thanks!

    • Brent Norris

      yep got rid of the 3 errors displayed in webmaster tools. thanks

  23. Abhishek Mishra

    Guys really you are amazing, yeah AMAZING.. this blog is really helpful for me ;)

  24. Jake Ratliff

    When I tried the htaccess method, it crashed my site. I just added this code into the htaccess file (via the Yoast plugin):

    # WordPress SEO – XML Sitemap Rewrite Fix

    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

    And then clicked the “save changes to .htaccess” button. I can’t go anywhere without the 500 error now. What did I do wrong? Anyone know how to fix this?

  25. Jake Ratliff

    I tried the htaccess fix and now I get a 500 Internal Server Error.

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

  27. Jérôme Lafforgue

    Thanks, work fine in wpseo-functions.php file @ line 461

  28. ast

    for me worked fine!
    thank you

  29. NicolasJoly

    @Matt Klein, it’s in the wpseo-functions.php file @ line 461

  30. NicolasJoly

    @Matt Klein, the ‘init’ function is now ‘wpseo_xml_sitemaps_init’ in the wpseo-functions.php, @line 461

    Add just :
    global $wp_rewrite; before the $GLOBALS define
    and
    $wp_rewrite->flush_rules(); after the add_rewrite_rule…

    /**

    * Initialize sitemaps. Add sitemap & XSL rewrite rules and query vars

    */

    function wpseo_xml_sitemaps_init() {

    $options = get_option( ‘wpseo_xml’ );

    if ( $options[‘enablexmlsitemap’] !== true ) {

    return;

    }

    // redirects sitemap.xml to sitemap_index.xml

    add_action( ‘template_redirect’, ‘wpseo_xml_redirect_sitemap’, 0 );

    if ( ! is_object( $GLOBALS[‘wp’] ) ) {

    return;

    }

    global $wp_rewrite;

    $GLOBALS[‘wp’]->add_query_var( ‘sitemap’ );

    $GLOBALS[‘wp’]->add_query_var( ‘sitemap_n’ );

    $GLOBALS[‘wp’]->add_query_var( ‘xsl’ );

    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’ );

    add_rewrite_rule( ‘([a-z]+)?-?sitemap.xsl$’, ‘index.php?xsl=$matches[1]’, ‘top’ );

    $wp_rewrite->flush_rules();

    }

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

  32. Regina Falkowski

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

  33. Alec Byrne

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

  34. Desainwebs

    Still not work for me

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

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

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

    -Scott

  38. 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.
    Thanks,
    Chris

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

  39. Shanthi Ganesan

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

  40. Lukas

    Nothing is working in my case – still Error 404 …

  41. Ryan

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

  42. lloyd

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

  43. Rosie

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

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

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

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