I'm using Rank Math to generate sitemap_index.xml. But sometimes the sitemap doesn't accessible and the URL shows a 404 error. As per rank math to use sitemap on the Nginx server we have to add the below code in the configuration file. So I don't know where the file is located and in which file I have to insert that code?
`# 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;

END Nginx Rewrites for Rank Math Sitemaps`


Configuration file link - https://help.dreamhost.com/hc/en-us/articles/216455077-Nginx-configuration-file-locations/

    david
    It says 'you may need to add the following code...' I'm using Rank Math myself and it doesn't require any extra settings/code for sitemap to work correctly on Nginx.

    8 months later
    9 days later

    Hi my website had the same issue with the sitemap when using rank math.
    I tried various solutions just as you are doing and nothing helped me.

    So I just disabled the sitemap of rankmath and installed another 3rd party xml sitemap plugin.
    Now everything is working fine.
    Now i dont get 404 pages and wrong redirects.

    Hosted by VirtuBox