When compared to any other web server, Nginx seems to be the most lightweight and one of the powerful alternative. Nginx server is much flexible and can handle high loads efficiently. But if not configured and writing permissions are not set properly, it can create a lot of hiccups. Today I will talk about one of the most common “Yoast SEO XML Sitemap 404 Not Found” Error on Nginx server.
Even personally, I went through this issue and figured a way out to fix up this problem. Basically, it happens, when Yoast SEO doesn’t have sufficient permission or the directory writing permission is not set properly. And in such cases, when you try to access your sitemap URL: domain.com/index_sitemap.xml, it shows error 404 sitemap not found.
Solved: Yoast XML Sitemap 404 Error
To deal with it, you need to add the following code to your Nginx server block.
Edit your Nginx sites-enabled directory and add the following code inside both of the server blocks for your domain.
rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last; rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
In case you’ve any subdirectory like domain.com/blog, you’ll still be getting yoast xml sitemap 404 not found for the directory.
For such scenarios, add the following code below inside your server blocks too. Otherwise skip this second part.
rewrite ^/blog/sitemap_index\.xml$ /blog/index.php?sitemap=1 last; rewrite ^/blog/([^/]+?)-sitemap([0-9]+)?\.xml$ /blog/index.php?sitemap=$1&sitemap_n=$2 last;
After all, your server blocks configuration should look like this.
Now check the Nginx configuration if there is an error or not by typing
If it’s successful, now restart your web server
service nginx restart
That’s all man, now we’ve fixed the yoast SEO XML sitemap 404 error on nginx server. Now visit your sitemap URL, it should work just fine.