Yoast XML Sitemaps on Apache servers

Last update: 15 January, 2018

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, 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
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.

Still not working?

If you've added the redirects above and the pretty permalinks do not load, the issue is likely another setting on your server. Please contact your webhost or server admin for assistance.

Was this article helpful? ·