Yoast XML Sitemaps on NGINX subfolder

If you have your WordPress site in a subfolder the official documentation won't help you unless you know a little bit of NGINX.

Here's the snippet to make Yoast SEO plugin XML feature work with a WordPress install inside a subfolder, in the example below would be inside a /blog/ subfolder.

server {
      # ... other configs ... 
      
      # Rewrites for Yoast SEO XML Sitemap
      rewrite ^/blog/sitemap_index\.xml$ /blog/index.php?sitemap=1 last;
      rewrite ^/blog/([^/]+?)-sitemap([0-9]+)?\.xml$ /blog/index.php?sitemap=$1&sitemap_n=$2 last;
}Code language: PHP (php)

Leave a Reply

Your email address will not be published. Required fields are marked *