WordPress Sitemap 404 Not Found Error with Nginx

Sitemap 404 Not Found

If you are using Nginx as your web server and install the Google XML Sitemap plugin on your WordPress site, then when you submit your xml sitemap to Goolge Search Console, you may get a WordPress sitemap 404 not found error.

sitemap 404 not found

 

The Solution

The solution is simple, just copy the following lines to your nginx virtual host file. On CentOS/Redhat Server, the virtual host file usually is /etc/nginx/conf.d/example.com.conf. On Debian/Ubuntu Server, it is located at /etc/nginx/sites-available/example.com

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;

Save the virtual host file and reload Nginx.

sudo systemctl reload nginx

or

sudo /etc/init.d/nginx reload

When you first installed Google XML Sitemap plugin, it will give a warning if you are using Nginx. The above rewrite rules can also be found when you go to Settings > XML-Sitemap.

Rate this tutorial
[Total: 2 Average: 3]

2 Responses to “WordPress Sitemap 404 Not Found Error with Nginx

Leave a Comment

  • Comments with links are moderated by admin before published.
  • Your email address will not be published.
  • Use <pre> ... </pre> HTML tag to quote the output from your terminal/console.
  • Please use the community (https://community.linuxbabe.com) for questions unrelated to this article.
  • I don't have time to answer every question. Making a donation would incentivize me to spend more time answering questions.

The maximum upload file size: 2 MB. You can upload: image. Links to YouTube, Facebook, Twitter and other services inserted in the comment text will be automatically embedded. Drop file here