1. Home
  2. Knowledge Base
  3. SEO Suite
  4. How To Exclude Rank Math Sitemaps from Caching

How To Exclude Rank Math Sitemaps from Caching

Caching is one of the easiest and effective ways to speed up your website. In WordPress, using 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, the sitemap of your website ends up being cached as well, 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 work for other plugins as well.

Let’s begin.

W3 Total Cache

To exclude Rank Math’s sitemap from being cached by W3 Total Cache, head over to Performance > Page Cache. There, enter the following code in the section, which says, “Never cache the following pages“.

sitemap?\.xml?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml

It is a simple regular expression that tells W3 Total Cache to exclude XML and XSL files with “sitemap” in the name.

Exclude Sitemap In W3 Total Cache

Since W3 Total Cache supports multiple types of caching, we have to make sure that none of those caching methods cache the sitemap. Here is what you need to do for the different cache types inside W3 Total Cache.

Database Caching

If you’re using database caching, head over to Performance > Database Caching > Never Cache the Following Pages and add the same strings there as well.

Exclude Sitemap In Database Cache W3 Total Cache

Minification

If you’re using minification with W3 Total Cache, head over to Performance > Minify > Never minify the following Pages and add the same strings there as well.

Exclude Sitemap In Minify W3 Total Cache

404 Error Exception List

W3 Total Cache also caches 404 errors on your website, which can lead to caching of the sitemap. To prevent this, head over to Performance > Browser Cache and add the same lines to the 404 error exception list.

Important Note: Recent versions of W3 Total Cache already have this exception added to the code, and you might see something similar on your website if you’re using the latest version.

Exclude Sitemap In 404 Exception W3 Total Cache

If you see this, the sitemap will be excluded already, and you don’t have to paste in the code snippet here.

LiteSpeed Cache

To exclude your sitemap being cached by LiteSpeed Cache, head over to LiteSpeed Cache > Cache > Excludes and enter the following code in the Do Not Cache URIs field.

/(.*)sitemap(.*).xml
/(.*)sitemap.xsl
/sitemap_index.xsl
/sitemap_index.xml

This will prevent and XML or XSL files from being cached.

Exclude Sitemap Caching In LiteSpeed Cache

WP Rocket

To exclude your sitemap from being cached by WP Rocket, head over to Settings > WP Rocket > Advanced Rules> Never Cache URL(s). Inside, enter the following code snippet and save your settings.

/(.*)sitemap(.*).xml
/(.*)sitemap.xsl

WP Super Cache

To exclude your sitemap from being cached by WP Super Cache, head over to WP Super Cache’s settings, then go to the Advanced Tab.

Head To Advanced Settings In WP Super Cache

Scroll way down to find the section which says, “Add here strings (not a filename) that forces a page not to be cached”. The section is not highlighted, so look carefully. Once you find it, add the following code snippet inside.

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.

Add Code Snippet To WP Super Cache

WP Fastest Cache

To exclude your sitemap from WP Fastest Cache, go to WP Fastest Cache > Exclude. In the exclude section, click the Add New Rule button in the Exclude Pages section.

Add New Rule In Exclude Tab In WP Fastest Cache

In the popup that appears, choose the contains option in the first dropdown, then type in sitemap in the text field next to it. Finally, save your settings.

Configure Sitemap Exclusion In WP Fastest Cache

Now WP Fastest Cache won’t cache your sitemaps.

CloudFlare

Many people also use Cloudflare on top of caching solutions to speed up websites, and it would be best if the sitemap was not cached by Cloudflare. The good news is that Cloudflare does not cache sitemaps by default, so you won’t have to do anything. However, if you’ve made some changes in the settings that are causing sitemaps to be cached, you can set a page rule inside your Cloudflare account and add the following code snippet there.

sitemap?\.xml?
[a-z0-9_\-]*sitemap[a-z0-9_\-]*\xml|xsl)?
([az0-9_\-]*?)sitemap([a-z0-9_\-]*)?.xml

Here is a support thread confirming this. Also, here is a guide by CloudFlare on how to use their page rules.

Other Caching Plugins

If you’re using any other caching plugins, then you’ll have to do some searching to find the solution. Most SEO plugins do offer this functionality, so you wouldn’t have much trouble. Also, the code snippet we shared is regex code, so any plugin supporting regex should be able to accept the code. If you can’t find solutions, you can always contact the plugin developer or your hosting provider for support.

Next Steps

No matter what caching plugin you’re using, make sure to save your changes and empty your cache after you’ve made these changes. Make sure to double-check if your settings were saved as many times you might navigate away from the page without explicitly saving your settings.

Was this article helpful?

Still need help?

?

Submit Your Question

Please give us the details, our support team will get back to you.

Open Ticket

Related Articles