Yoast XML Sitemaps on Apache servers

Last update: 02 August, 2017

Our plugin generates the 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 see here.

How do I know if I need to add the redirect 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
Remember that you might have to modify this if you are running WordPress in a subfolder. For instance, if you run it in a subfolder called /wordpress/, this would be the proper code.

Was this article helpful? ·