[Fixed] Why Does Yoast Not Generate A Sitemap – Sitemap_index.xml 404

3.7
(3)

So I have been struggling to fix a problem with my sitemap. It was working properly before, until I moved the server.

The problem is I didn’t know up until this morning. I moved my site to the new server two weeks ago.

And Google noticed that too:

sitemap-404 error

That doesn’t look good, does it?

So I, like you guys right now, search the web for a solution. I was running Rankmath. I tried to change to Yoast SEO and other sitemap plugins but still the 404 error persisted.

By the way, my site is on an Nginx server.

Yoast SEO  has a post here showing the solution or half of the solution. They provided the code below but didn’t tell where to put the code:

location ~ ([^/]*)sitemap(.*).x(m|s)l$ {
  ## this rewrites sitemap.xml to /sitemap_index.xml
  rewrite ^/sitemap.xml$ /sitemap_index.xml permanent;
  ## this makes the XML sitemaps work
  rewrite ^/([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 last;
  rewrite ^/sitemap_index.xml$ /index.php?sitemap=1 last;
  rewrite ^/([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 last;
  ## The following lines are optional for the premium extensions
  ## News SEO
  rewrite ^/news-sitemap.xml$ /index.php?sitemap=wpseo_news last;
  ## Local SEO
  rewrite ^/locations.kml$ /index.php?sitemap=wpseo_local_kml last;
  rewrite ^/geo-sitemap.xml$ /index.php?sitemap=wpseo_local last;
  ## Video SEO
  rewrite ^/video-sitemap.xsl$ /index.php?xsl=video last;
}

I put it in the server block, didn’t work.

Then I tried to put this inside the location / block inside the server block and the problem was solved.

nginx configuration to fix sitemap 404 error

Remember to put the configuration block inside location /

And that’s all the fix needed to make your sitemap.xml working again.

 

Click on a star to rate it!

Average rating 3.7 / 5. Vote count: 3

No votes so far! Be the first to rate this post.


Leave a Reply

Your email address will not be published. Required fields are marked *