Home Experience & Tips Sharing Standard Post

Standard Post

Solution for All in One SEO Pack plugin sitemap.xml 404 error

I believe many people use the Google XML Sitemaps plugin to generate sitemap.xml files for their websites. Naiba used to do the same. Later, I found that the All in One SEO Pack actually comes with a sitemap generation component, so I stopped using Google XML Sitemaps to generate it.

Updated on November 1, 2019 About 4 minutes read
All in One SEO Pack插件sitemap.xml 404的解决办法

I believe many people use the Google XML Sitemaps plugin to generate sitemap.xml files for their websites. Naiba used to do the same. Later, I found that the All in One SEO Pack actually comes with a sitemap generation component, so I stopped using Google XML Sitemaps to generate it.

Suddenly found that sitemap.xml returned 404. Switching to Google XML Sitemaps also returned 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 toSolution for sitemap.xml file 404

The occurrence of 404 is basically a problem with pseudo-static configuration.

For example, while writing this article, I suddenly discovered that when I was tinkering with file caching, I also cached the xml file. Removing the caching rule solved the problem.

Solution for sitemap.xml 404

A safer method is to add pseudo-static rules for sitemap.xml

The following two pseudo-static rules have been tested and are effective.

Nginx rules 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

Just add the above pseudo-static rule to your virtual host's nginx configuration file, and then restart nginx.

For LNMP one-click package users, directly add it above the line include rewrite/wordpress.conf;

For Baota Panel users, just add the above code to the pseudo-static rules of your website.

Other Considerations

If you are using a caching plugin, remember to add both of the following pages to the exception list to prevent visitors from encountering errors when accessing cached pages.

sitemap.xml
sitemap.xsl

5/5 - (2 votes)
Previous Add a line segment mouse attraction effect to a WordPress website Continue reading content around the same timeline. Next Highly Recommended WordPress Speed Optimization Plugin: Hummingbird View the next related tutorial or experience.

AI Website Building Assistant

🤖
Hello! I am the Naibabiji AI Assistant. How can I help you?
Quick Consultation: