All in One SEO WordPress plugin dynamic sitemap.xml not working with nginx

Sitemaps have become an integral part of the modern website and of course WordPress has a good amount of plugins for creating sitemaps and keeping them up-to-date. In the past most of the plugins would create and update sitemap.xml file, however, this is nowadays changing and you can see more and more plugins rather generating the sitemap dynamically upon request instead of storing it in a file. This is also the case with the XML Sitemaps feature of the popular All in One SEO plugin.

Once you enable XML Sitemaps in the All in One SEO’s Feature Manger you may find out that your sitemap.xml is actually not working and returning 404 not found (or other) error. There could be many different reasons for that but if you ar running your site with nginx (always a good choice!) the issue could be you are missing these few lines in your nginx server config section for your domain:

rewrite ^/sitemap.xml$ /index.php?aiosp_sitemap_path=root last;
rewrite ^/sitemap_(.+)_(\d+).xml$ /index.php?aiosp_sitemap_path=$1&aiosp_sitemap_page=$2 last;
rewrite ^/sitemap_(.+).xml$ /index.php?aiosp_sitemap_path=$1 last;

just add them, test the config with nginx -t and reload/restart nginx as usual. Of course if you have no idea what all this is about and whether you use nginx, apache or something else, you should the issue you have with your server/site administrator.