Wildcarding images in Cloudflare means using the asterisk (*) symbol in a Cache Rule or Page Rule to match every image URL on your site, so Cloudflare caches them at the edge instead of fetching them from your origin server every time. This is done through Cloudflare’s Cache Rules (the current tool) or the older Page Rules, both accessible from the Rules section of your dashboard.
Cache Rules are Cloudflare’s current recommended method, since Page Rules are being phased out for new configurations. The process below covers both, along with the file-extension approach that avoids wildcard limitations entirely.
Setting Up a Cache Rule for All Images
Cache Rules are the modern replacement for Page Rules and offer more precise control over what gets cached and for how long.
Open Rules in your Cloudflare dashboard. Navigate to Rules > Overview, then select Cache Rules from the available rule types.
Create a new rule and set your match condition. Rather than relying on a URL wildcard, match by file extension (jpg, png, gif, webp, svg, etc.) using the “URI Path” field with an “ends with” or “matches regex” operator. This approach is more reliable than a path-based wildcard because it catches images regardless of which folder they’re stored in.
Set the cache eligibility to “Eligible for cache.” This tells Cloudflare to cache matching requests rather than passing them straight through.
Set an Edge Cache TTL. Choose how long images should stay cached at Cloudflare’s edge before being re-fetched from your origin — a longer TTL reduces origin load but delays how quickly updated images appear.
Save and deploy the rule. Cloudflare applies rules in priority order, so if you have other cache rules, make sure this one is positioned where it won’t be overridden by a broader rule above it.
Cloudflare also offers ready-made templates that simplify this setup. One-click Cache Rules templates let you create optimized cache rules instantly, eliminating the complexity of manual rule configuration — including a template that replicates Page Rules caching behavior by making only default file extensions eligible for cache.
Using a Legacy Page Rule Instead
If you’re still using Page Rules, wildcards work directly in the URL pattern field, though this method is being deprecated in favor of Cache Rules.
A Page Rule matches a URL pattern based on five segments — scheme, hostname, port, path, and query string — and you can use an asterisk in any of these segments to indicate a wildcard for matching specific patterns. For images specifically, community guidance confirms this works at the file-extension level too: you can use an asterisk to match only .jpg, .css, or other file types, for example matching sub.example.com/directory/*.jpg to cache all .jpg files.
To wildcard an entire images directory, set your Page Rule’s URL match to something like example.com/images/* and set the setting to “Cache Level: Cache Everything.” Keep in mind that Page Rules are limited in number on lower-tier plans, so a single broad rule covering an images folder is more efficient than creating one rule per file type.
Why Extension Matching Beats Broad Wildcards
A common mistake is wildcarding an entire path (like /images/*) instead of targeting file extensions, which can unintentionally catch non-image content served from the same directory, such as JSON data or HTML pages used for image galleries.
It’s also worth noting that Cloudflare already caches many static file types by default, independent of any custom rule. Certain extensions are already cached by default, so a custom images rule mainly matters for extensions or paths that fall outside that default list, or when you want to override the default cache duration.
A Known Limitation With Wildcards in Cache Rules
If you’re migrating from Page Rules to Cache Rules, be aware that wildcard support isn’t identical between the two systems. Cache Rules dropped support for wildcards on URI paths in the way Page Rules allowed — a pattern like /fee//fii// that worked as a Page Rule can’t be replicated the same way using an asterisk in Cache Rules. For this reason, matching by file extension (as described above) or using regex-based match conditions is generally the more dependable approach going forward.
Common Setup Mistakes to Avoid
- Forgetting to proxy your DNS records. Cache Rules require your domain or subdomain to be proxied through Cloudflare — a “DNS only” (grey cloud) record won’t get cached regardless of your rule setup.
- Placing a broad rule above a specific one. If you need special handling for a subfolder of images, that more specific rule needs a higher priority than your catch-all rule, or it will never be evaluated.
- Assuming a wildcard bypasses origin cache headers. Cloudflare still respects your origin server’s cache headers unless you explicitly override them with an Edge Cache TTL setting in the rule.
Purging Wildcarded Image Caches
Once images are cached broadly, you’ll eventually need to clear that cache after updating a file. Cloudflare offers several targeted purge options instead of clearing everything. You can purge by host to clear all resources for a hostname, purge by prefix to clear everything under a specific URL path, or purge by tag — all of which work independently of any custom cache key you’ve configured.
Join The Discussion
Have you run into issues migrating an image-caching wildcard rule from Page Rules to Cache Rules, or found a match pattern that works better than file-extension matching? Share your setup or any troubleshooting tips below.