How to prevent sitemaps from being cached
Most cache plugins will by default be configured not to cache sitemap files. In the rare case your plugin or server is caching any sitemap, please add an exclusion for the sitemap files to your cache plugin. The steps vary by cache plugin, so in this article, we’ll explain how you can add an exclusion for the sitemaps per plugin.
When finished, be sure to clear your cache from your plugin, theme, server, browser, or CDN such as Cloudflare. If you are not sure how to clear your server caching, please speak with your host provider. If you need to clear your browser cache, this guide on how to clear your browser’s cache may help.
Table of contents
How to prevent sitemaps from being cached in W3 Total Cache
To prevent sitemaps from being cached in W3 Total Cache, follow these steps. By default, W3 Total Cache does not cache the Yoast sitemaps, but enabling certain features may cause sitemaps to be cached.
- If you’ve ticked Do not process 404 errors for static objects with WordPress, add the code in step 2
- Under 404 exception list, add the code below
sitemap(_index)?\.xml(\.gz)?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl|html)(\.gz)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml - Click Save Settings
- Go to Minify
- Under Never minify the following pages, add the code below
sitemap(_index)?\.xml(\.gz)?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl|html)(\.gz)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml - Click Save Settings
How to prevent sitemaps from being cached in WP Super Cache
To prevent sitemaps from being cached in WP Super Cache, follow the instructions below.
- In your WordPress Dashboard, go to Settings
- Go to WP Super Cache
- Under Advanced, go to Rejected URL Strings
- Add the code below
index\.php
sitemap(_index)?\.xml(\.gz)?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl|html)(\.gz)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml - Click Save Strings
How to prevent sitemaps from being cached in WP Rocket
WP Rocket offers sitemap preloading. To prevent WP Rocket from caching the sitemaps, follow the instructions below.
- In your WordPress Dashboard, go to to Settings
- Go to WP Rocket
- Go to Advanced Rules
- Under Never Cache URL(s), add the following code
/(.*)sitemap(.*).xml
/(.*)sitemap.xsl - Click Save changes
How to prevent sitemaps from being cached in other cache plugins or methods
If you are using a different plugin or caching is done at the server level, please contact the plugin developer or your hosting company for support.