Family Encyclopedia >> Electronics

How to Fix Yoast SEO Sitemap 404 Errors in WordPress: Proven Solutions

Downloaded over 1 million times, Yoast SEO remains the most comprehensive WordPress SEO plugin available. While it's reliable on our sites, some users face 404 errors on XML sitemaps due to theme or plugin conflicts. We've successfully resolved this for clients—here's how.

Key Note: This issue usually arises from poorly coded plugins or themes, not Yoast itself, which performs flawlessly in our experience.

Start by editing your .htaccess file (accessible via FTP, cPanel, or your host's file manager). Add these rewrite rules:

# 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

This fixes the problem for most users. In one case, however, Google Search Console still detected 404 headers despite the page loading.

As a non-ideal but effective workaround, edit the core file at /wp-content/plugins/wordpress-seo/inc/class-sitemaps.php. Update the init() function like this:

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]', ' ');
    $wp_rewrite->flush_rules();
}

This adds the global $wp_rewrite reference and a flush_rules() call, resolving the 404 on our client's site. We're surprised Yoast doesn't include this by default, given user reports in comments.

Update: After applying, some users must disable the sitemap option in Yoast SEO settings, save, then re-enable and save again to fully resolve it.

We hope this guide saves you time—it's battle-tested from real-world fixes.