Nginx server build WordPress using Rank Math SEO plugin to generate Sitemaps need to do additional settings

Rank Math creates a sitemap dynamically, which relies on using redirects at the server level. In some cases, you will need to manually add some rewrite rules if your sitemap is not working as expected.

To make sure you need to add these rewrite rules, go to domain.com?sitemap=1.

Check sitemap generation in Rank Math

If the sitemap loads successfully, it means that Rank Math SEO was able to generate the sitemap successfully, but was unable to rewrite the sitemap to the sitemap_index.xml page.

Fix sitemap issue with Rank Math SEO on Nginx server

If the Nginx server prevents the creation of sitemap files, then Rank Math will also let you know via a notification under sitemap settings. In this case, you need to add the rewrite rule manually.

Rank math sitemap notifications on Nginx servers

1. Add rewrite rules to the Nginx server

So go to the Nginx configuration file and add the following rewrite rule to fix the problem:

Modify the corresponding nginx site configuration file, usually in /usr/local/nginx/site-enables/xxx.

  • Editing configuration files with vim
  • Add the plugin's rewrite code before the } at the end.
  • Save file
  • Restart Nginx with the command systemctl restart nginx
Editing configuration files with vim
Add the plugin's rewrite code before the } at the end.
Save the file
Restart Nginx with the command systemctl restart nginx
# 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. Clear sitemap settings

After adding the above rewrite rule, you need to refresh the sitemap settings. To do this, go to Rank Math SEO → sitemap settings in the WordPress admin area and make some minor changes to the "Number of links per sitemap". Then click the "Save Changes" button.

Refresh sitemap setting

Reference:https://rankmath.com/kb/xml-sitemaps-nginx/

Leave a Comment

en_USEnglish