Latest Tech and Tips

How to Fix Yoast’s WordPress SEO Sitemap 404 Error


Are you getting a 404 error when making an attempt to view your sitemap? If you’re utilizing Yoast SEO, this may occur. In this text, we’ll present you ways to simply repair Yoast’s SEO sitemap 404 error.

Yoast SEO is among the hottest SEO plugins for WordPress, however generally it may possibly battle with different plugins or themes in your web site.

One of our earlier shoppers bumped into the difficulty of getting a 404 error for his or her sitemaps generated by Yoast’s WordPress SEO plugin. After making an attempt a number of issues, we have been ready to determine the answer.

First factor you need to attempt is open your .htaccess file. You can use a plugin like Htaccess File Editor to edit your htaccess file out of your WordPress dashboard.

We advocate making a backup of your WordPress web site earlier than making any modifications, as even a small typo may carry down your web site.

Once you’ve put in the plugin, go to Settings » WP Htaccess Editor. Make positive to learn the directions earlier than you click on the “I understand. Enable the editor” button.

enable the htaccess editor

After you allow the editor, merely add the next code in there, on the backside:

# 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]
# END WordPress SEO - XML Sitemap Rewrite Fix

For most individuals this mounted the difficulty. Someone reported that whereas this code mounted the difficulty, the web page was nonetheless sending the 404 response header which meant that Google Webmasters software couldn’t discover it.

If that doesn’t repair the 404 sitemap subject, you could want to attempt one other methodology. While not most well-liked, in our consumer’s case we had no alternative however to edit the core plugin recordsdata to repair the difficulty. As steered by hadjedj.vincent, we edited the class-sitemaps.php positioned in “/wp-content/plugins/wordpress-seo/inc/class-sitemaps.php”.

You want to have a look at the operate init() code and make that part appear like this:

	 * Initialize sitemaps. Add sitemap rewrite guidelines and question var
	operate init() {
		international $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', 'high' );
		add_rewrite_rule( '([^/]+?)-sitemap([0-9]+)?.xml$', 'index.php?sitemap=$matches[1]&sitemap_n=$matches[2]', 'high' );

Basically what we’re doing is including the worldwide $wp_rewrite; at the start that’s already there and including flush_rules after the code. By including this within the plugin, it mounted the sitemap 404 subject on our consumer’s web site.

Some of our customers reported that after making use of the above repair, they nonetheless wanted to uncheck the sitemap choice within the Yoast’s SEO plugin and save their settings. After that re-checking the sitemap’s choice mounted the error for them.

If you have been searching for a repair to your sitemap 404 subject, we hope that this repair has helped you! You may additionally need to try our comparability of Yoast SEO vs. AIOSEO.

If you favored this text, then please subscribe to our YouTube Channel for WordPress video tutorials. You can even discover us on Twitter and Facebook.