🔥 Holiday Sale! 25% Off Platinum Membership and up to 50% Off on Deployarr (ends December 31).

[Solved] WordPress Yoast SEO sitemap blank on Nginx

After moving my WordPress blog to Nginx on Digital Ocean, I have had to work through a few issues, one of it being Yoast SEO sitemap blank problem. Likes most bloggers I use Yoast's WordPress SEO plugin, which sort of eliminates the need for several other plugins for non-on-page SEO functions. One such function is XML sitemap generation. Yoast sitemap blank issue is different from the sitemap 404 error, which is more common. In my case the XML sitemap page was blank with nothing on it. If you came here trying to find answer to Yoast SEO sitemap blank problem then read on. [Read: 5 blogging mistakes I made when I started this blog]

Yoast SEO Sitemap Blank Problem

The pictures below describe the problem. As you can see the sitemap.xml file generated by Yoast's WordPress SEO plugin is blank. If the sitemap is non-functional, it can cause issues with Google indexing your site properly or in a timely manner.

Wordpress Yoast Seo Sitemap Blank
Wordpress Yoast Seo Blank Sitemap

When I disabled W3 Total Cache, I could see the individual sitemap links but they were unformatted and were not linked. Visually this was a problem. [Read: Fix for WordPress blank page with the word “error”]

Wordpress Yoast Xml Sitemap Blank - No Style
Wordpress Yoast Xml Sitemap - No Style

When I viewed the sitemap's HTML source code, it was wasn't empty and it had what it is supposed to have. And when I check with sitemap with some of the sitemap validators I did not find any issues. So the problem was only visual.

Yoast Xml Sitemap Source
Yoast Xml Sitemap Source

But I wanted to fix this Yoast XML sitemap blank problem anyways. So here is what I did to make the WordPress SEO sitemaps work normally on Nginx webserver.

Recommended Guides on WordPress:

Fix for Yoast XML Sitemap Blank Issue

The WordPress SEO plugin, upon activation, provides you the rewrite rules for Nginx web server. But additional rewrite rules are needed to make the XML sitemap generation part of the plugin work fully. The blank XML sitemap is due to the main-sitemap.xsl (XML stylesheet) being not redirected correctly. This is easily solved by adding the following rewrite rule to Nginx host file within the server blocks:

rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;

If you are interested in seeing all the Nginx rewrite rules that I use to make the WordPress SEO plugin work correctly then take a look at the code block below:

# This rewrite redirects sitemap.xml to sitemap_index.xml, which is what Yoast's WordPress SEO plugin generates.
rewrite ^/sitemap\.xml$ /sitemap_index.xml permanent;
 
# This rewrite ensures that the styles are available for styling the generated sitemap.
rewrite ^/([a-z]+)?-?sitemap\.xsl$ /index.php?xsl=$1 last;
 
# These rewrites rule are generated by Yoast's plugin for Nginx webserver.
rewrite ^/sitemap_index\.xml$ /index.php?sitemap=1 last;
rewrite ^/([^/]+?)-sitemap([0-9]+)?\.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;

I have uploaded this code to my Gist repository in case you would like to fork it or improve it. [Read: 6 FeedBurner tweaks to spruce up your WordPress feed delivery]

W3 Total Cache Settings to Prevent Yoast Sitemap Blank Problem

In addition to the Nginx rewrites to fix Yoast SEO sitemap blank bug, you also need to configure your W3 Total Cache correctly and apply necessary exclusions to avoid caching or minifying your sitemap and related files. Add the following code to Page Cache (Never cache the following items), Minify (Never minify the following items), Browser Cache (404 Error Exception List), and CDN (Rejected Files) sections of W3 Total Cache.

([a-z0-9_\-]+)?sitemap(_index)?(-)?([0-9]*)?\.(xml(\.gz)?|xsl)$

The above code is also available on my Gist repository for rework. Here is a screenshot of where the above line of code needs to go in W3 Total Cache settings.

W3 Total Cache Settings For Yoast Xml Sitemap On Nginx
W3 Total Cache Settings For Yoast Xml Sitemap On Nginx

Once you entered your rewrite rules and added necessary settings to your W3 Total Cache configuration go ahead and restart your Nginx webserver and clear any caches. This should have solved your Yoast SEO sitemap blank problem.

Be the 1 in 200,000. Help us sustain what we do.
128 / 150 by Dec 31, 2024
You will gain benefits such as Deployarr access, discord roles, exclusive content, ad-free browsing, and more.
🔥 Holiday Sale! 25% Off Platinum Membership $399.99 $299.99 (ends December 31).
Join the Geek Army (starting from just $1.67/month)

Anand

Anand is a self-learned computer enthusiast, hopeless tinkerer (if it ain't broke, fix it), a part-time blogger, and a Scientist during the day. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs.

Holiday Sale