Hi, for Nginx you’ll need to make make sure that all requests that do not get satisfied (meaning: there is no static file called sitemap-news.xml) get then redirected to index.php
It actually depends on your existing Nginx rules where/what should be done to fix this.
You can find basic Nginx rules for WordPress sites on https://www.ads-software.com/support/article/nginx/ where the main rule that does this, can be found in the example wordpress.conf file:
location / {
# This is cool because no php is touched for static content.
# include the "?$args" part so non-default permalinks doesn't break when using query string
try_files $uri $uri/ /index.php?$args;
}
which basically means: first try for a static file (and then the same location with a trailing slash) and then divert to index.php
Once at index.php, it will be WordPress itself that treats the request ??
In short, the default Nginx setup for WordPress sites should work fine. But… if you have for example a custom rule to set a high browser cache ttl for static files, including the xml
extension, then you might accidentally disabled this “try static file first, then divert to index.php” for those type of requests.
I suspect this is the case on your server. Change the .xml extension to .jpg for example, accessing /sitemap-news.jpg this will show the same Nginx 404 response. But if you remove the extension or set a fictitious one (like /sitemap-news.xyz) then you get a 404 page generated by WordPress.
You’ll have to look through all your Nginx rules and find the rule that targets a bunch of file extensions which could look like:
location ~* \.(ogg|ogv|svg|svgz|eot|otf|woff|mp4|ttf|css|rss|atom|js|jpg|jpeg|gif|png|ico|zip|tgz|gz|rar|bz2|doc|xls|exe|ppt|tar|mid|midi|wav|bmp|rtf|swf)$ {
add_header "Access-Control-Allow-Origin" "*";
access_log off;
log_not_found off;
expires max;
}
and check if you see |xml
in that list. You can then simply remove that little |xml
, save the file and reload Nginx. Or you can look a bit further to find the rule that specifically targets sitemaps. There must be such a rule because your /sitemap.xml redirects to /sitemap_index.xml which then works fine. Or does Rankmath create static sitemap files?
If you need help with specific rule, you can paste in in a reply here and I’ll try to make sense of it for you ??