SEO by Yoast – Fix Sitemap XML error on Nginx

Q. I had problem with WordPress SEO by Yoast sitemap XML that running on Nginx web server. When i tried to display the sitemap XML via the URL, It’s giving me a 404 error as below.

WordPress SEO by Yoast sitemap XML

A. In order to fix above WordPress SEO by Yoast sitemap XML error on Nginx web server, please do the following steps :

1. Login to your Nginx web server via ssh access or ftp access :

2. Adding the following in side of your Nginx server block to enable the rewrite rules :

rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

3. This step is optional, just in case Step 2 above did not resolve your issue. Try to add the following to .httaccess file in your document root folder :

rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

Leave a Reply