Yoast XML Sitemaps on Apache servers
Our plugin generates sitemaps dynamically when you enable the sitemap feature. In some cases, you may need to add server level redirects if you receive an Apache server error or a wrong page when loading the XML sitemaps. If you are using NGINX, please use the rules here.
Table of Contents
How do I know if I need to add the rewrite rules?
The Yoast SEO XML sitemap URL uses a pretty permalink of example.com/sitemap_index.xml but, behind the scenes, this URL also has a non-pretty permalink of example.com/?sitemap=1. If you can load and see the sitemap using the non-pretty permalink, your server is not setup to redirect and, thus, you'll need to add redirect rules.
What are the Apache redirect rules?
You should go to your .htaccess file ( How to Guide available here.) and add the following code before the main WordPress rewrite rules:
# Yoast SEO - XML Sitemap Rewrite Fix RewriteEngine On RewriteBase / RewriteRule ^sitemap_index.xml$ /index.php?sitemap=1 [L] RewriteRule ^locations.kml$ /index.php?sitemap=wpseo_local_kml [L] RewriteRule ^geo_sitemap.xml$ /index.php?sitemap=geo [L] RewriteRule ^([^/]+?)-sitemap([0-9]+)?.xml$ /index.php?sitemap=$1&sitemap_n=$2 [L] RewriteRule ^([a-z]+)?-?sitemap.xsl$ /index.php?xsl=$1 [L] # END Yoast SEO - XML Sitemap Rewrite Fix
Still not working?
If you've added the redirects above and the pretty permalinks do not load, the issue is likely to do with other settings on your server. Please contact your
webhost or server admin for assistance.