Steps to resolve Yoast’s SEO sitemap 404 error in wordpress

Steps to resolve Yoast’s SEO sitemap 404 error in wordpress

Steps to resolve Yoast’s SEO sitemap 404 error in wordpress

One of the best WordPress SEO Plugin is Yoast SEO. It has more number of comprehensive tools that optimizes your website completely. This plugin shows all types of hidden errors technically to boost SEO any difficulties. Unfortunately, recent surveys say that some users are getting 404 errors when they generate a sitemap using the Yoast SEO plugin.

This type of error is not fully dependent on the Yoast SEO plugin in some cases. Maybe some poor theme coding gives you 404 errors? Let’s see the steps one by one:

Open .htaccess file:

Go to the WordPress SEO plugin and then choose the edit file. You can access .htaccess file after clicking on the option “edit file”.

Just add below-mentioned code in your .htaccess file:

Code:
# 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
Once this code executed, your problem will be solved. Still, few users complain that the website page shows 404 errors even if the coding is good. In addition to this, Google Webmaster couldn’t find the pathway for sitemap.

Now, we have the only option to configure core plugin files just by editing the class-sitemaps.php this problem will be solved. So, you can view the class-sitemaps.php file in the path /wp-content/plugins/wordpress-seo/inc/class-sitemaps.php

Cross-check init() whether it looks as same as below:

Code:
/**
* 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();
}
You can ask like what urges this code to run for solving 404 errors? Yeah! You have a great idea to deal with the errors 404 by adding global $wp_rewrite; in top and flush_rules() at the last. This eradicates the 404 error from your website page. Try this solution to get the easy opening of the Yoast SEO sitemap.
Author
bhawanisingh
Views
6,317
First release
Last update
Rating
0.00 star(s) 0 ratings
Top