Skip to content

Page Rules — URL Pattern Matching & Actions in Cloudflare

DodaTech Updated 2026-06-23 5 min read

In this tutorial, you'll learn about Page Rules. We cover key concepts, practical examples, and best practices to help you understand and apply this topic effectively.

Cloudflare Page Rules let you define URL patterns and apply specific actions such as cache control, security settings, and performance optimizations to matching requests at the network edge.

What You'll Learn

By the end of this tutorial, you will understand Page Rules syntax, how to create and order rules, and how to use the most common actions for Caching, redirects, and security headers.

Why It Matters

Page Rules give you granular control over how Cloudflare handles traffic to different parts of your site. Instead of applying one policy globally, you can customize behavior for specific URL patterns.

Real-World Use

Doda Browser uses URL-based rules to treat different website categories differently. Similarly, Page Rules let you cache static assets aggressively while bypassing the cache for dynamic API endpoints.

Your Learning Path

flowchart LR
  A[Prefetch & Preload] --> B[Page Rules Intro]
  B --> C[Page Rules Caching]
  C --> D[Page Rules URL Forwarding]
  D --> E[More Cloudflare Features]
  B --> F{You Are Here}
  style F fill:#f90,color:#fff

Page Rules Basics

A Page Rule consists of a URL pattern and one or more actions. When a request URL matches the pattern, Cloudflare applies the configured actions in the order specified.

URL Pattern Syntax

Pattern Matches
example.com Homepage only
*example.com/* All pages on all subdomains
example.com/images/* Everything under /images/
example.com/*.jpg All JPEG images
example.com/blog/202?/* Blog posts from 2020-2029

Creating a Page Rule

  1. Log in to the Cloudflare dashboard.
  2. Select your domain.
  3. Go to Rules > Page Rules.
  4. Click Create Page Rule.
  5. Enter your URL pattern and select actions.
  6. Set the priority (rules are evaluated from top to bottom).
  7. Save and deploy.

Common Page Rule Actions

flowchart TD
  A[Incoming Request] --> B{Matches Page Rule?}
  B -->|Yes| C{Action Type}
  C -->|Cache| D["Cache Level / Bypass / Edge TTL"]
  C -->|Security| E["SSL / WAF / Browser Integrity"]
  C -->|Performance| F["Minify / Rocket Loader / Polish"]
  C -->|Redirect| G["Forwarding URL / Redirect"]
  C -->|Misc| H["Custom Headers / IP Geolocation"]
  B -->|No| I[Default Cloudflare settings]

Practical Examples

Example 1: Aggressively Cache Static Assets

# Pattern: example.com/assets/*
# Actions:
#   - Cache Level: Cache Everything
#   - Edge Cache TTL: 30 days
#   - Browser Cache TTL: 30 days

# Result: All assets under /assets/ are cached at the edge
# for 30 days with no origin requests for returning visitors

Example 2: Bypass Cache for Admin Area

# Pattern: example.com/admin/*
# Actions:
#   - Cache Level: Bypass
#   - Security Level: High
#   - Browser Integrity Check: On

# Result: Admin pages are never cached.
# Security is elevated and bot detection is enabled.

Example 3: Always Use HTTPS

# Pattern: *example.com/*
# Actions:
#   - Always Use HTTPS: On

# Result: Every visitor is redirected from HTTP to HTTPS
# regardless of subdomain or path. This is a single rule
# that replaces individual redirect configurations.

Rule Priority and Ordering

Page Rules execute from top to bottom. If a request matches multiple rules, only the first matching rule (highest priority) applies.

// Simulating Page Rules priority logic
const pageRules = [
  { pattern: '*example.com/admin/*', action: 'bypass_cache' },
  { pattern: '*example.com/*.jpg', action: 'cache_everything' },
  { pattern: '*example.com/*', action: 'auto_minify' },
];

function matchRule(url) {
  for (const rule of pageRules) {
    if (url.match(rule.pattern.replace('*', '.*'))) {
      console.log('Matched:', rule.pattern, '->', rule.action);
      return rule.action;
    }
  }
  return 'default';
}

console.log(matchRule('https://example.com/admin/dashboard'));
// Expected output:
// Matched: *example.com/admin/* -> bypass_cache

Common Errors

Wrong pattern syntax. Omitting the wildcard * causes the rule to match only the exact URL. Use *example.com/* to cover all subdomains and paths.

Too many Page Rules. Free plans include 3 rules, Pro plans include 50, and Business plans include 125. Use regular expressions in a Cloudflare Worker for complex logic beyond the rule limit.

Conflicting rules. Two rules that match the same URL but set different cache levels cause unpredictable behavior. Review your rule list for overlaps.

Caching dynamic content unintentionally. A broad cache rule that matches API endpoints or admin pages can serve stale data. Always test with a narrow pattern first.

Rule not applied immediately. Page Rules propagate within 30-60 seconds across the Cloudflare network. Clear the browser cache and use a fresh incognito session to verify changes.

Practice Questions

  1. What wildcard character does Cloudflare use in Page Rule URL patterns?
  2. How does Page Rule priority work when a request matches multiple patterns?
  3. Why should you use *example.com/* instead of example.com for site-wide rules?

Challenge

Create a Page Rule Strategy for a website with the following requirements: cache all static assets for 30 days, bypass cache for the /admin/ path, always use HTTPS, and enable Auto Minify for all pages. Determine the minimum number of rules needed and their priority order.

Real-World Task

Audit your current Cloudflare Page Rules. Identify any rules that overlap or conflict. Reorder them to ensure the most specific patterns appear first and the most general patterns appear last.

FAQ

Can Page Rules override Cloudflare settings at the zone level?

Yes. Page Rules take precedence over zone-level settings. If a zone-level setting enables Auto Minify but a Page Rule disables it for a specific path, the Page Rule wins for matching requests.

How many actions can I add to a single Page Rule?

You can add multiple actions to a single Page Rule. There is no hard limit, but Cloudflare recommends keeping each rule focused on one objective to avoid unexpected interactions between actions.

Do Page Rules affect API calls to my domain?

Yes, unless you use a separate API subdomain. All HTTP requests to your domain pass through Page Rule evaluation. Consider using a dedicated subdomain like api.example.com for API traffic to keep rules clean.

  • Page Rules Caching — Cache control strategies with Page Rules
  • Page Rules URL Forwarding — Redirects and URL rewriting
  • Cloudflare — Complete platform guide

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro — security-first tools for the modern web.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro