How do I prevent sitemaps from being cached?

Last update: 06 October, 2017

Please add an exclusion for the sitemap files to your cache plugin. The steps vary by cache plugin so please select your cache plugin below.

Table of Contents

W3 Total Cache

If you're using the setting "Do not process 404 errors for static objects with WordPress", please add the following exception:

([a-z]+)?-?sitemap.xsl

If you're using W3 Total Cache to minify your pages, please input the same exception as above to the "Never minify the following pages:" setting under Minify > Advanced:

WP Super Cache

Go to Settings  > WP Super Cache and click on the Advanced tab.  Scroll down to the section where it says “Add here strings (not a filename) that forces a page not to be cached” and enter the following string in the box:

sitemap(_index)?\.xml(\.gz)?
([a-z0-9_\-]+)?sitemap\.xsl
[a-z0-9_\-]+-sitemap([0-9]+)?\.xml(\.gz)?

WP Rocket

Go to WP Rocket > Advanced Options and scroll down to the section where it says “Never cache the following pages”.  Enter the following strings in the box:

([a-z]+)?-?sitemap.xsl

Other Cache Plugin or Method

If you are using a different plugin or caching is done at the server level then contact the plugin developer or your hosting company for support.

Exclude the following formats:

sitemap(_index)?\.xml(\.gz)?
([a-z0-9_\-]+)?sitemap\.xsl
[a-z0-9_\-]+-sitemap([0-9]+)?\.xml(\.gz)?

Was this article helpful? ·