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 All in One SEO Pack actually includes a sitemap generation component within its features, so Google XML Sitemaps was no longer used 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 setting an 8-day cache for xml caused the 404; excluding xml from the cache should fix it.) Below is how to
Solution for sitemap.xml file 404. The occurrence of a 404 is basically due to pseudo-static configuration issues. For example, while writing this article, I suddenly realized it was because I had cached xml files while tinkering with file caching; removing the caching rule should fix it.
Solution for sitemap.xml 404
更
A safer method is to add pseudo-static rules for sitemap.xml. Both of the following pseudo-static 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;
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 for Adding Nginx Pseudo-Static Rules
Simply add the above pseudo-static rules to your virtual host's nginx configuration file, then restart nginx. For users of the LNMP one-click installation package, directly add it above the line `include rewrite/wordpress.conf;`. For Baota Panel users, add the above code in your website's pseudo-static rules section.
Other Considerations
If you are using a caching plugin, remember to add the following two pages as exceptions to prevent 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.