I believe many people use the Google XML Sitemaps plugin when generating sitemap.xml files for their websites. Naiba used to as well, but later discovered that the All in One SEO Pack functionality actually includes a built-in sitemap generation component, so I stopped using Google XML Sitemaps for generation. Just now, I suddenly found that sitemap.xml returned a 404 error, and switching to Google XML Sitemaps also resulted in a 404.
Not sure what the reason was, but I've been tinkering with file caching these past two days(Looking at the rules, it should be that the xml file was set to cache for 8 days, causing the 404. Excluding xml from caching should fix it.) Below is the
solution for sitemap.xml file 404. The occurrence of 404 is basically due to rewrite rule configuration issues. For example, while writing this article, I suddenly realized that it was because I had cached xml files when tinkering with file caching. Removing the caching rule should solve it.
Solution for sitemap.xml 404
更
A safer method is to add rewrite rules for sitemap.xml. The following two rewrite rules have been tested and are effective. The nginx rule recommended by the Google XML Sitemaps plugin
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml$ "/index.php?xml_sitemap=params=$2" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.xml\.gz$ "/index.php?xml_sitemap=params=$2;zip=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html$ "/index.php?xml_sitemap=params=$2;html=true" last;
rewrite ^/sitemap(-+([a-zA-Z0-9_-]+))?\.html.gz$ "/index.php?xml_sitemap=params=$2;html=true;zip=true" last;
The rule recommended by All in One SEO Pack
#rewrite rules for AIOSEOP XML Sitemap
rewrite ^/sitemap.xml$ /index.php?aiosp_sitemap_path=root last;
rewrite ^/sitemap_(.+)_(\d+).xml$ /index.php?aiosp_sitemap_path=$1&aiosp_sitemap_page=$2 last;
rewrite ^/sitemap_(.+).xml$ /index.php?aiosp_sitemap_path=$1 last;
rewrite ^/sitemap.xml.gz$ /index.php?aiosp_sitemap_path=root.gz last;
rewrite ^/sitemap_(.+)_(\d+).xml.gz$ /index.php?aiosp_sitemap_path=$1.gz&aiosp_sitemap_page=$2 last;
rewrite ^/sitemap_(.+).xml.gz$ /index.php?aiosp_sitemap_path=$1.gz last;
Method to add Nginx rewrite rules
Simply add the above rewrite rules to your virtual host's nginx configuration file and restart nginx. For LNMP one-click installation package users, directly add it above the line `include rewrite/wordpress.conf;`. Baota Panel users, add the above code in your website's rewrite rules.
Other considerations
If you are using a caching plugin, remember to add both of the following pages as exceptions to avoid errors when visitors access cached pages. sitemap.xml
sitemap.xsl
Comments are closed
The comment function for this article is closed. If you have any questions, please feel free to contact us through other channels.