Caching is one of the easiest and most effective ways to enhance your website’s speed. In WordPress, caching is as simple as installing a caching plugin and configuring some basic settings.
However, this usually leads to a problem. When caching is enabled, your website’s sitemap may also be cached, which is the opposite of what should happen. Since a sitemap should always be up to date with the pages, posts, and custom posts on your website, caching it defeats the purpose.
That is why we’ll show you how to exclude the sitemap generated by Rank Math from being cached. We will cover the most popular caching plugins, but the methods should also work for other plugins.
Let’s begin.
Jump To:
1 htaccess
Before making any changes to your cache plugin’s settings, you should add a rewrite rule to your .htaccess file and confirm if it resolves the issue. To do that, navigate to Rank Math SEO → General Settings → Edit .htaccess from your WordPress dashboard.

Editing your site’s .htaccess file can cause your site to break if you make any mistakes. Hence, Rank Math displays a warning and keeps the text area disabled to avoid any accidental edits.
You can add the below code to the text area once you click the checkbox below the warning. Once done, click Save Changes.
Note: You can use the htaccess tester tool to debug and ensure the rewrites are correct before adding them to the .htaccess file.
RewriteEngine On
RewriteRule .* - [E=Cache-Control:no-cache]

The next step is to confirm whether your sitemap is excluded from the cache. If not, proceed with the steps below to change your cache plugin’s configuration.
2 WP Rocket
To exclude your sitemap from being cached by WP Rocket, head over to Settings → WP Rocket → Advanced Rules → Never Cache URL(s). Once done, enter the code snippet below and save your settings.
/(.*)sitemap(.*).xml
/(.*)sitemap.xsl
3 W3 Total Cache
To exclude Rank Math’s sitemap from being cached by W3 Total Cache, head over to Performance → Page Cache from your WordPress dashboard. Then, enter the code below in the ‘Never cache the following pages’ settings. Once done, click Save all settings to save your changes.
sitemap(_index)?\.xml(\.gz)?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\.(xml|xsl|html)(\.gz)?
([a-z0-9_\-]*)?\.xml
The above code is a simple regular expression (regex) that instructs W3 Total Cache to exclude all XML and XSL files with the string “sitemap” in their name from being cached.

Since W3 Total Cache supports multiple caching methods, ensure that none of them cache the sitemap. Here is how to do that for the different cache types inside W3 Total Cache.
3.1 Database Caching
If you use database caching, head over to Performance → Database Cache. Then, scroll to the Never cache the following pages option and add the code snippet, as shown below. Once done, click Save all settings.

3.2 Minification
If you use minification in W3 Total Cache, navigate to Performance → Minify. Then, scroll down to the Never minify the following pages option and paste the code snippet, as shown below. Once done, click Save all settings.

3.3 404 Error Exception List
W3 Total Cache also caches 404 errors on your website, which can result in the sitemap being cached. To prevent this, head over to Performance → Browser Cache. Then, add the code snippet to the 404 error exception list settings, as shown below. Once done, click Save all settings.
Note: Recent versions of W3 Total Cache include this code snippet in the 404 error exception list by default. In that case, you don’t need to add another code snippet.

4 LiteSpeed Cache
To exclude your sitemap from being cached by LiteSpeed Cache, navigate to LiteSpeed Cache → Cache → Excludes in your WordPress dashboard. Once done, paste the code snippet below into the ‘Do Not Cache URIs’ field and click Save Changes.
/(.*)sitemap(.*).xml
/(.*)sitemap.xsl
/sitemap_index.xsl
/sitemap_index.xml

5 WP Super Cache
To exclude your sitemap from being cached by WP Super Cache, navigate to Settings → WP Super Cache → Advanced in your WordPress dashboard.

Once done, navigate to Rejected URL Strings and paste the below code snippet. Then, click Save Strings.
sitemap?\.xml?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*.(\xml|xsl)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml
Here is how it should appear for you once the code snippet is added.

6 WP Fastest Cache
To exclude your sitemap from WP Fastest Cache, navigate to WP Fastest Cache → Exclude from your WordPress dashboard. In the Exclude Pages settings, click Add New Rule, as shown below.

In the Exclude Page Wizard pop-up, select Contains in the dropdown menu and type sitemap into the text field. Once done, click Save, as shown in the image below.

7 Cloudflare
Cloudflare does not cache sitemaps by default. However, if you’ve made some changes that cause your sitemaps to be cached, you can set a page rule to exclude your sitemap from being cached.
To do this, log in to your Cloudflare account and select your website. Then, navigate to Rules → Page Rules and click Create Page Rule, as shown below.

In the Page Rules settings, paste your sitemap URL in the URL field. Then, select “Cache Level” and “Bypass” from the dropdown menus. Once done, click Save and Deploy Page Rule.
Note: If you navigate to Rank Math SEO → Sitemap Settings from your WordPress dashboard, your sitemap URL will be displayed at the top of the General settings page.

8 Hummingbird Cache
To exclude your sitemap from Hummingbird Cache, navigate to Hummingbird → Caching → Page Caching from your WordPress dashboard.

In the Page Caching settings, navigate to Exclusions and paste the below code snippet. Once done, click SAVE SETTINGS.
sitemap[^\/.]*\.xml

9 Transient Cache
Sometimes the sitemap can be affected by a server-level cache. In such a case, you can add the below filter to your theme’s rank-math.php file to exclude your sitemap from being cached. You can refer to this guide on adding filters to a WordPress site.
/**
* Filter if XML sitemap transient cache is enabled.
*
* @param boolean $unsigned Enable cache or not, defaults to true
*/
add_filter( 'rank_math/sitemap/enable_caching', '__return_false');
10 Other Caching Plugins
If you’re using other caching plugins, you’ll have to do some research to find a solution. Most caching plugins allow you to disable your sitemap from being cached, so you wouldn’t have much trouble finding a solution.
Additionally, the code snippets we shared are regular expression (regex) codes, so any plugin that supports regex will accept them. If you can’t find a solution, contact the plugin developer or your hosting provider for support.
Next Steps
No matter what caching plugin you use, ensure to save your changes and empty your cache after you’ve made these changes. Be sure to double-check that your settings were saved, as you may navigate away from the page without saving them.
Also, to ensure your sitemap updates properly and avoids 404s or stale content, flush both Rank Math’s internal sitemap cache and WordPress permalinks:
- Go to Rank Math SEO→ Sitemap Settings, adjust the Links Per Sitemap field (e.g., change it to 201), then click Save Changes. This forces the sitemap cache to regenerate.
- Then, navigate to Settings → Permalinks and click Save Changes (without making any other changes). This refreshes rewrite rules and resolves sitemap accessibility issues.
You can see how to do that below:

And that’s it! If you have any doubts or need help with Rank Math, don’t hesitate to reach out to our dedicated support team. They’re available 24/7, 365 days a year.