Home » Blogging » [Solved] WordPress Yoast SEO sitemap blank on Nginx

[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 Reading:

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[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[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[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-z[a-z0-9_\-]itemap(_index)?(-)?([0-9[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.

We Are Hiring: Familiar with Media Streaming, HTPC, Home Server, Smart Home, and Home Automation topics? Write about it and earn money. No writing experience needed. APPLY HERE.

Get 20% OFF with IPVanish VPN:

♦   Hide your browsing and streaming activity: No logs and no tracking
♦   Access geo-restricted content from anywhere
♦   Encrypt and anonymize: Kodi, Plex, Downloads, Personal Info
♦   Windows, Mac, Linux, Android, iOS, Router, and more.
♦   Money back guarantee - Sign Up Now

About the author

Anand

Anand is a self-learned computer enthusiast, a part-time blogger, and a Food Scientist by career. He has been blogging since 2010 on Linux, Ubuntu, Home/Media/File Servers, Smart Home Automation, and related HOW-TOs on htpcbeginner.com and smarthomebeginner.com.

Archives

Join the other 110,000 followers

Don’t Miss Out!