Start a project
WooCommerce

Prevent WP Rocket from Caching Filtered WooCommerce pages

· by Daniel

When using WP Rocket with preloading in combination with a filter plugin like Filter Everything pro, then your database AND cache folder can explode. We had a site with only around 2000 Products, but with 100 filterable product attributes.

This resulted in wp_rocket_cache table over 2 million entries and the cache folder going up to 200GB. To fix this, we decided to stop wp rocket from caching filtered WooCommerce category pages.

The following code snippet solved our problem:

add_filter( 'rocket_preload_exclude_urls', function( $regexes, $url ) {
    $url = untrailingslashit( $url );
    if(function_exists('is_filtered')){
        if ( is_filtered() ) {
            $regexes[] = $url;
            add_filter( 'do_rocket_generate_caching_files', '__return_false' );
        }
    }
    if(function_exists('flrt_is_filter_request')){
        if ( flrt_is_filter_request() ) {
            $regexes[] = $url;
            add_filter( 'do_rocket_generate_caching_files', '__return_false' );
        }
    }
    return $regexes;
}, 10, 2 );

Update 2025

In addition to the code above you should add this one below. Amazonbot for example is heavily crawling sites and you can block amazonbot with .htaccess and then also not cache filtered URLs + not generating CSS.

function disable_cache_for_filtered_urls() {
   if ( function_exists( 'flrt_is_filter_request' ) && flrt_is_filter_request() ) {
       if ( ! defined( 'DONOTCACHEPAGE' ) ) {
           define( 'DONOTCACHEPAGE', true ); // Disable WP Rocket caching
       }
   }
	if(function_exists('is_filtered') && is_filtered()){
       if ( ! defined( 'DONOTCACHEPAGE' ) ) {
           define( 'DONOTCACHEPAGE', true ); // Disable WP Rocket caching
       }
	}
}
add_action( 'template_redirect', 'disable_cache_for_filtered_urls' );

.htaccess code

# Block Harmful Robot

    RewriteEngine On
    RewriteCond %{HTTP_USER_AGENT} (amazonbot|semrushbot|ahrefsbot) [NC]
    RewriteRule (.*) - [F,L]

# END Block Harmful Robot

Questions & answers (3)

  1. Sean ReinartOctober 20, 2025

    This is an incredibly useful and well-explained solution — thank you for sharing it! 🚀 The combination of WP Rocket’s aggressive preloading and filter-based URLs can indeed spiral out of control fast, and your approach neatly prevents that. I especially appreciate how you’ve covered both the PHP filter logic *and* the .htaccess layer for crawler control — it’s a clean, practical fix that’ll save developers countless headaches (and gigabytes!). Excellent optimization tip for WooCommerce sites with complex filtering setups.

  2. ErastJune 24, 2025

    Does not work. the filter pages continue to be cached. how to fix it?

  3. Joep van GoolMarch 5, 2025

    Unfortunately doesn’t seem to work in 2025

More articles

All articles →
WooCommerceOctober 29, 2026 EmpCo Directive: What Online Shops Must Know About Green Claims Since 27 September 2026 “Sustainable”, “climate-neutral shipping”, “eco-friendly packaging”: claims like these appear in many online shops – in product texts, banners, badges in the footer or in carbon of… WooCommerceApril 20, 2022 How to Reactivate old WooCommerce PayPal Standard Gateway WooCommerce has replaced the old PayPal Standard Payment Gateway since version 5.5. WooCommerceMay 23, 2021 How to Hide Prices & Add to Cart + Enquiry in WooCommerce Learn how to remove prices & the add to cart button in WooCommerce. In addition we show you how you can add an enquiry form instead.

Let's increase your online sales.

Tell us about your shop or website. A developer replies, not a sales team.

★ 4.85/5 from 800+ ratings · Envato Elite Author · Made in Germany