If you are using WordPress SEO plugin from Yoast to generate XML sitemaps on your WordPress site running on Nginx, the sitemap could be loaded without any style information. This is due to a missing rewrite rule.
If your site is running on Nginx and if you turn on XML sitemaps from the WordPress SEO plugin, it will provide you with two Nginx rewrite rules.
Once the two rewrite rules have been added to Nginx and if you try to load the XML sitemaps from a browser, the sitemap will get loaded, but with errors. On Firefox, it got rendered as plain text. On Chrome, the page was blank. And if you tried to monitor the HTTP requests and responses using developer tools, you will notice a 404 error while retrieving the main-sitemap.xsl
file. The main-sitemap.xsl
file is the XML stylesheet that contains the presentation information. Without this file, the browser will not know how to display the XML sitemap properly.
The workaround for this problem is to add an additional rewrite rule to Nginx. Append the following rewrite rule immediately after the default Nginx rewrite rules provided by the WordPress SEO plugin.
1 |
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last; |
Once the rule is in effect, the browser will load the XML sitemaps correctly.