Sitemap rewrite rules for NGINX

Some configurations of NGINX require rewrite rules to be added to the NGINX configuration file.

If you're getting a 404 Page Not Found error for your XML Sitemap, RSS Sitemap or Video Sitemap on NGINX, then please add the following rewrite rules in your NGINX config file.

NOTE:  If you don't know what to do with these, then you'll need to contact your hosting company for support.

rewrite ^/video-sitemap.xml$ /index.php?aiosp_video_sitemap_path=root last;
rewrite ^/video-sitemap.xml.gz$ /index.php?aiosp_video_sitemap_path=root last;
rewrite ^/(.+)-video-sitemap.xml$ /index.php?aiosp_video_sitemap_path=$1 last;
rewrite ^/(.+)-video-sitemap.xml.gz$ /index.php?aiosp_video_sitemap_path=$1 last;
rewrite ^/(.+)-video-sitemap(\d+).xml$ /index.php?aiosp_video_sitemap_path=$1&aiosp_sitemap_page=$2 last;
rewrite ^/(.+)-video-sitemap(\d+).xml.gz$ /index.php?aiosp_video_sitemap_path=$1&aiosp_sitemap_page=$2 last;

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

rewrite ^/sitemap.rss$ /index.php?aiosp_sitemap_path=rss last;
rewrite ^/sitemap.latest.rss$ /index.php?aiosp_sitemap_path=rss_latest last;

NOTE:  The Video Sitemap rules must always come before the XML Sitemap rules.

You might also need to use these rewrite rules if /sitemap.xml keeps redirecting to you to /sitemap_index.xml, which is the sitemap slug of a competing SEO plugin. You'll also need to remove the rewrite rules for that specific plugin.

*These rules will work for 99% of users. In some cases, such as if you have WordPress installed in a subdirectory, there may be modifications you'll need to make.

If this doesn't work for you, then please contact us.