Hello,
I apologize for the inconvenience you are facing with your multilingual website’s sitemap. It seems that extra URLs are being added to the sitemap, causing 404 errors.
To resolve this issue, you can add the following piece of code anywhere in your theme’s functions.php file:
add_filter( 'rank_math/sitemap/url', function( $url, $object ) {
if ( strpos( $url, '/fr/' ) !== false ) {
return $url;
}
return '';
}, 10, 2 );
This code snippet will help exclude the unwanted URLs from the sitemap that are causing 404 errors. Please add this code to your theme’s functions.php file.
If you need further assistance or have any other questions, feel free to ask.
Thank you for reaching out and providing the screenshot.
Sources:
Multilingual SEO with Rank Math SEO & WPML » Rank Math
Rank Math Sitemap Issues and Their Fixes » Rank Math
Why the Sitemap_Index.xml is Throwing a 404 Error » Rank Math
Rank Math Sitemap Issues and Their Fixes » Rank Math
Rank Math Sitemap Issues and Their Fixes » Rank Math
Hello,
For initial troubleshooting, please follow these steps to flush your sitemap cache:
1. Flush the Sitemap cache by following this video screencast:
https://i.rankmath.com/pipRDp
2. Exclude the Sitemap files of the Rank Math plugin in your caching plugin. The cache could be via a plugin or from the server. For plugins or Cloudflare, please follow this article:
https://rankmath.com/kb/exclude-sitemaps-from-caching/
3. Disable the transient cache for the sitemap by applying this filter. This will make sure that your XML sitemap always reflects the latest changes on your site:
/**
* Filter if XML sitemap transient cache is enabled.
*
* @param boolean $unsigned Enable cache or not, defaults to true
*/
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
If you’re not sure how to add this code, you can follow this guide:
https://rankmath.com/kb/wordpress-hooks-actions-filters/
Let us know how this goes.
Hello,
Since we did not hear back from you for 15 days, we are assuming that you found the solution. We are closing this support ticket.
If you still need assistance or any other help, please feel free to open a new support ticket, and we will be more than happy to assist.
Thank you.