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.
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”]
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.
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.
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.
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.
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.
IPVanish VPN Exclusive Offer - only $3.99 per month:
Windows, Android, Ubuntu
OSMC on RPi
♦ Hide your browsing (no logs), Anonymize Streaming and Downloads
♦ Circumvent Geo/Country Restrictions and access worldwide content
♦ Works on Windows, Mac, Linux, Android, iOS, Router, and more
♦ 250 GB of SugarSync Secure storage included
♦ Money back guarantee - Sign Up Now