Rank Math creates a virtual sitemap dynamically that relies on using redirects on the server-level. In certain situations where your sitemap appears not to be working as intended, you’ll need to add some rewrite rules manually.
To ensure that you need to add these rewrite rules, go to domain.com?sitemap=1.
If your sitemap loads, then it means Rank Math is able to successfully generate the sitemap of your website but, it is unable to rewrite the sitemap to
Fix Sitemap Issues on Nginx Server
If your Nginx server is preventing the creation of the sitemap file, then Rank Math would also let you know through a notice under Sitemap Settings. In that case, you need to manually add the rewrite rules.
1 Add Rewrite Rules to Nginx Server
So head over to your Nginx config file and add the following rewrite rules to fix this:
# START Nginx Rewrites for Rank Math Sitemaps rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last; rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last; rewrite ^/([a-z]+)?-sitemap\.xsl$ /index.php?xsl=$1 last; # END Nginx Rewrites for Rank Math Sitemaps
2 Flush Sitemap Settings
Once you’ve added the above rewrite rules, you’ll need to flush your sitemap settings. To do so, head over to Rank Math > Sitemap Settings in your WordPress admin area and make any minor changes to the Links Per Sitemap count. Then click the Save Changes button.
3 Flush Permalinks
Next, navigate to WordPress Dashboard > Settings > Permalinks. You don’t need to make any changes here. Just click the Save Changes button.
4 Exclude Sitemap from Caching
Once you’ve flushed your Sitemap Settings, ensure that you’ve excluded your sitemap from caching. If you haven’t already done so, you can refer to this dedicated knowledgebase article to help you with it.
5 Disable Transient Caching
/** * Filter if XML sitemap transient cache is enabled. * * @param boolean $unsigned Enable cache or not, defaults to true */ add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
And, that’s it! We hope that this article has helped you resolve any potential issues with using Rank Math’s XML Sitemap on servers running Nginx. However, if you are still facing problems or have any queries please feel free to contact our support team and we’d be happy to help you at any given time.