A Request Passes Through Multiple Rule Phases
Imagine a parcel moving through a sorting hub. At each station a clerk photographs the parcel as it arrives, then works only from that photograph. If the clerk at station three repacks the box, the clerk at station four still reads station four's own photograph — taken when the parcel reached them, showing the repack. Nobody consults a single master description of the parcel, and nobody can reach back and change an earlier photograph.
Cloudflare's request pipeline works like that. Each station is a phase: a fixed stage in the life of a request, defined by Cloudflare and not reorderable by customers. Each phase holds one or more rulesets, and a ruleset is an ordered list of rules. A rule is a filter expression plus an action. The photograph is the field snapshot: the values of every request field as they exist when that phase begins.
Take one request: GET https://shop.example.com/collections/sale?utm_source=email. A realistic zone might have all of the following configured at once, and every one of them addresses a different stage.
| Configured rule | Phase | What it does to this request |
|---|---|---|
| Single Redirect | http_request_dynamic_redirect | Sends /collections/sale to /collections/clearance |
| URL Rewrite | http_request_transform | Maps /collections/* to /catalog/* |
| Configuration Rule | http_config_settings | Turns off Rocket Loader for /collections/* |
| Origin Rule | http_request_origin | Routes /collections/* to a legacy backend |
| WAF custom rule | http_request_firewall_custom | Blocks paths containing /catalog/admin |
| Cache Rule | http_request_cache_settings | Marks /collections/* eligible for cache with a 60-second edge TTL |
| Worker route | After the rule phases | Handles every request on shop.example.com/* |
These do not compete in one list. Each belongs to a different phase, and phases run in a fixed order. Figure 1 traces the request through the application-layer request phases, with the two exits that end it early.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','titleColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
C["GET shop.example.com/collections/sale"] --> R["http_request_dynamic_redirect
Single Redirects"]
R -->|"match"| X["3xx + Location
request ends here"]
R -->|"no match"| N["http_request_sanitize
URL normalization"]
N --> T["http_request_transform
URL Rewrite Rules"]
T --> CFG["http_config_settings
Configuration Rules"]
CFG --> O["http_request_origin
Origin Rules"]
O --> WAF["http_request_firewall_custom
WAF custom rules"]
WAF -->|"block or challenge"| B["403 or challenge
request ends here"]
WAF -->|"no match"| RL["http_ratelimit
Rate limiting rules"]
RL --> MR["http_request_firewall_managed
WAF Managed Rules"]
MR --> H["http_request_late_transform
Request Header Transform Rules"]
H --> CS["http_request_cache_settings
Cache Rules"]
CS --> WK{"Worker route
on this hostname?"}
WK -->|"yes"| WH["Worker handles request;
fetch() subrequest re-enters cache"]
WK -->|"no"| CL{"Cache lookup"}
WH --> CL
CL -->|"hit"| Z["Response from edge cache"]
CL -->|"miss"| OR["Origin receives final path,
Host, headers, port"]
OR --> Z
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class O,WAF,MR,OR primary;
class C,R,X,N,T,CFG,B,RL,H,CS,WK,WH,CL secondary;
class Z ok;
Order creates two surprises. First, a redirect runs before any rewrite, so a redirect expression always sees the URL the visitor typed. Second, WAF custom rules run after the rewrite phase, so they evaluate the rewritten path, not the visible one. Neither behavior is a bug; both are consequences of where each product's phase sits.
Figure 2 draws the same pipeline as layers, with the snapshot boundary marked at each hand-off. The browser and the origin each hold a different idea of the URL, and the edge is the only place where both ideas are visible at once.
A Worker is not one of these phases. When a route matches, the Worker becomes the request handler after the rule phases and before the zone cache is consulted. If it calls fetch(), that subrequest passes through the cache with cache rules evaluated against the subrequest's URL, not the visitor's. This is why a cache rule can appear to be ignored by a Worker: it matched the inbound request, but the response was keyed on something else.
DNS sits at the same boundary. Origin Rules choose which hostname is resolved, so a DNS-record override changes where the request is sent without changing the URL the browser shows.
Three semantic families exist inside this order, and they do not share a precedence rule.
Value-setting actions change a field: rewrite the path, set a header, override the origin, set a cache TTL. Within one phase, the last matching rule's value wins for that setting. Terminating actions — redirect, block, challenge, serve error — stop evaluation and reply immediately, so the first matching rule wins.
Skip removes evaluation, not access
A skip rule grants nothing and stops nothing by itself. It removes named products, rulesets, or phases from evaluation, and later phases run only if the options it selected allow them to.
One zone can run two evaluation models
Within a phase, account-level rules run before zone-level rules, and account-level phases are currently Enterprise-only. Page Rules are not a phase at all: they are a legacy layer that modern rules override and Workers suppress. That is where silent skips come from.
Matching Fields Can Change After a Rewrite
The snapshot rule has a sharp edge. Within a phase, no rule sees what an earlier rule in that phase just changed.
Rules in one phase do not compose
Two rules in the same phase can both match, but the later one replaces the earlier value instead of building on it. There is no chaining inside a phase: the second rule still reads the phase's opening snapshot.
Across phases, changes do propagate. That is the point of the snapshot hand-off, and it is where most precedence bugs live. Run one request through a realistic tangle:
The two failures mirror each other. Step 5 is the classic silent skip: nothing errors, nothing warns, the rule simply never matches again after an unrelated rewrite ships. Step 4 is its mirror image, a rule that starts firing on traffic it was never written for.
The table compares what each phase actually reads once a rewrite has run.
| Stage (phase) | Field the expression usually tests | Value seen after the rewrite | What to test instead |
|---|---|---|---|
Single Redirect (http_request_dynamic_redirect) | http.request.full_uri | Original URL — a redirect ends the request, so no rewrite ever coexists with it | Nothing; this is the last phase that sees the visitor's URL |
URL Rewrite (http_request_transform) | http.request.uri.path | Original URL for the first matching rule; later rules in the same phase still see the original | raw.http.request.uri.path when composing with other products |
WAF custom rules (http_request_firewall_custom) | http.request.uri.path, http.request.uri.query | Rewritten path and query | raw.http.request.uri.path to match what the visitor requested |
Origin Rules (http_request_origin) | http.host, http.request.uri.path | Rewritten path; host unchanged unless a configuration rule changed it | raw.http.request.uri.path plus raw.http.host |
Cache Rules (http_request_cache_settings) | http.request.uri.path, http.request.host, cookies, headers | Rewritten path; header values set in the late-transform phase | raw.* fields, or key on a header that no rule modifies |
Request Header Transform (http_request_late_transform) | http.request.headers | Headers as they arrived; a header set by an earlier rule in this phase is invisible to later rules | Order rules deliberately and set each header once |
The escape hatch is the raw field family. Fields prefixed raw. are immutable for the whole request workflow, so raw.http.request.uri.path keeps reporting the path the visitor sent no matter how many rewrites run.
Use the same raw expression on both sides
Cloudflare documents this explicitly as the fix for rewrites breaking later rules, and recommends the same raw expression in both the rewrite and the downstream rule. Figure 3 shows the two failure branches that appear when the raw field is omitted.
%%{init: {'theme':'base','themeCSS':'.edgeLabel .label text, .edgeLabel text, .edgeLabel span { fill:#132440 !important; color:#132440 !important; }','themeVariables': {'primaryColor':'#16476A','primaryTextColor':'#ffffff','primaryBorderColor':'#132440','secondaryColor':'#3B9797','secondaryTextColor':'#ffffff','secondaryBorderColor':'#132440','tertiaryColor':'#c4873b','tertiaryTextColor':'#132440','tertiaryBorderColor':'#132440','lineColor':'#5a6e82','textColor':'#132440','mainBkg':'#16476A','nodeBorder':'#132440','clusterBkg':'#eef3f7','clusterBorder':'#132440','edgeLabelBackground':'#ffffff','actorBkg':'#16476A','actorTextColor':'#ffffff','actorBorder':'#132440','activationBkgColor':'#3B9797','activationBorderColor':'#132440','signalColor':'#5a6e82','signalTextColor':'#132440','noteBkgColor':'#c4873b','noteTextColor':'#132440','noteBorderColor':'#132440','labelBoxBkgColor':'#a8dede','labelBoxBorderColor':'#132440','labelTextColor':'#132440','loopTextColor':'#132440','altBackground':'#f8f9fa','fontFamily':'DM Sans, sans-serif'}}}%%
flowchart TD
A["Request /help/old/start"] --> B{"Redirect phase
full_uri matches?"}
B -->|"yes"| X["3xx to visitor
rewrite never runs"]
B -->|"no"| C["Rewrite phase:
/help/old/* to /help/new/*"]
C --> D["New snapshot for later phases
path is now /help/new/start"]
D --> E{"WAF rule tests
/help/new/ ?"}
E -->|"yes"| F["Fires on a path nobody typed
possible false block"]
E -->|"no"| G{"Origin rule tests
/help/old/ ?"}
G -->|"stopped matching"| H["Silent skip: default origin,
no error, no log"]
G -->|"raw field used"| I["Correct backend"]
D --> J["Cache Rule keys on new path"]
J --> K["Duplicate cache entry
old entry keeps serving"]
classDef primary fill:#132440,color:#ffffff,stroke:#0b172b;
classDef secondary fill:#16476A,color:#ffffff,stroke:#0f314a;
classDef ok fill:#3B9797,color:#ffffff,stroke:#2a6f6f;
classDef danger fill:#BF092F,color:#ffffff,stroke:#7a0420;
classDef warn fill:#c4873b,color:#132440,stroke:#8a5a1f;
class E,G primary;
class A,B,X,C,D,I,J,K secondary;
class F,H danger;
Loud versus quiet failures. A false block is loud, because the visitor sees a 403. A silent origin miss is quiet, because the page still renders — from the wrong server. Prefer raw. fields on any expression that must describe the visitor's request rather than the pipeline's current state, and reserve mutable fields for rules that intentionally react to earlier phases.
Product boundaries matter. The regex matches operator is limited to Business and Enterprise; Origin Rules can override host, SNI, and resolved DNS only on Enterprise, while destination-port overrides work on every plan. Cache Rules quotas vary by plan. Check the availability table before designing around a field or override, and note the date you checked.
Overlapping Actions Need Product-Specific Precedence
Here is a Page Rule that a great many zones still run:
- URL pattern:
*example.com/assets/* - Cache Level: Cache Everything
- Edge Cache TTL: 1 day
- Host Header Override:
assets-backend.example.net
A Page Rule is one ordered bundle. Its three actions run in the order the customer chose inside the rule. The modern equivalent is not one rule; it is two, in two different phases:
The translation is not behavior-preserving, for three reasons. The origin override now runs before cache settings instead of wherever the bundle placed it. "Eligible for cache" enables Cache Everything by default, so a rule written to replicate a narrow Page Rule can start caching HTML that was never cached. And first-match-wins does not carry over: modern cache rules stack, and the last matching rule wins for any conflicting setting.
That last point is the misconception worth naming plainly.
Last match wins is scoped to one phase
"Last match wins" is not a property of modern Rules; it is a property of non-terminating actions inside a single phase. Redirects, blocks, challenges, and serve-error actions terminate: the first match stops the pipeline and replies. A team that applies one precedence rule to every action will mispredict every redirect and every WAF block in the zone.
Figure 4 separates the two models. On the left, a Page Rule is one ordered bundle applied at a single point. On the right, each modern action lands in its own phase, inherits that phase's snapshot, and obeys that phase's precedence class.
Precedence is a short decision procedure, not a single ranking:
- Phase order decides who goes first. Redirect, then sanitize, then transform, then configuration, then origin, then WAF custom rules, then rate limiting, then Managed Rules, then late header transforms, then cache settings, then snippets.
- Account before zone within the same phase, where account-level phases are available.
- Within a phase, for value-setting actions, the last matching rule wins per setting. Cache Rules merge; if two rules disagree on cache eligibility, the later one decides.
- Within a phase, for terminating actions, the first match wins and evaluation stops. If two redirect products could both match, the earlier phase wins — Single Redirects before Bulk Redirects.
- Skip removes evaluation, and it is scoped. A zone-level skip affects zone-level phases; an account-level skip affects only account-level configuration.
- Page Rules lose to modern rules on the same path, and lose entirely when a Worker handles the request.
Two operational failures follow directly from paths that other systems already own.
Rules that capture platform paths
A redirect matching /cdn-cgi/* intercepts the challenge platform's own requests and produces a challenge loop. Exclude /cdn-cgi/challenge-platform/ from any rule that challenges or redirects broadly.
A redirect matching /.well-known/* breaks HTTP domain control validation and custom hostname verification, so certificate renewals fail weeks later with no visible link to the rule. Both failures are precedence working as designed.
Migration Requires Behavior Tests Rather Than Syntax Replacement
Translating syntax is the easy half. A Page Rule pattern such as *example.com/assets/* becomes an expression, and the dashboard will even offer templates that fill it in. The hard half is that the translated rule now participates in a different evaluation model, and three classes of behavior change are invisible in a syntax diff.
First-match becomes stackable. A Page Rule won because it was first. A modern rule with the same expression competes with every other rule in its phase, and a broad catch-all placed later will override it. The migration question is not "what did this rule do" but "what else now matches the same request, and in what order".
A bundle becomes a phase-ordered set. Actions that ran in a customer-chosen sequence now run in Cloudflare's fixed sequence. An origin override that used to happen after cache settings may now happen before them. When the actions are independent the difference is invisible; when one action's input is another's output, it is decisive.
Defaults drift. "Eligible for cache" turns on Cache Everything, which the equivalent Page Rule required explicitly. A faithful-looking translation can therefore start caching HTML responses that were never cached, including pages with personalized fragments.
Some boundaries resist syntax replacement entirely. Workers suppress Page Rules but not modern rules, so migrating with a Worker on the route changes which actions apply. Legacy WAF Managed Rules and legacy Rate Limiting cannot be disabled by modern rules, so "Disable Security" Page Rules have no complete equivalent. And the migration guide's 30 October 2026 revision still calls automatic migration "planned" for late 2025 or beyond — verify current status rather than assume it has passed.
Figure 5 shows the same intent under both models and the failure path that a syntax-only migration walks into.
The practical method is a behavior test, not a review. Build the modern rule disabled and simulate the request in Rules simulator to see the evaluation order and confirm which rules match. The simulator is in Beta, requires an Administrator or Super Administrator role, and does not display rules bypassed automatically for operational reasons such as certificate validation paths. Then enable the modern rule alongside a disabled Page Rule, drive real traffic, and compare what each version actually returns.
Compare across conditions, not once. The comparison has to hold across methods, cookies, query strings, bot user agents, and at least one authenticated session before the Page Rule is switched off — and only after a further observation window should it be deleted.
The tradeoff is honest: more precision, more surfaces to test. Replacing syntax without testing behavior has not migrated anything; it has deployed a hypothesis.
Trace Three Overlapping Rule Configurations
The exercise below is design-only. It has not been executed for this article, no zone was modified, and no measurements are reported. Everything labeled "expected" is a prediction derived from the documented phase order, to be confirmed on your own zone.
Trace Three Overlapping Rule Configurations
Status: design-only, not executed. Prerequisites: a zone you control with a proxied DNS record; access to Rules, Cache Rules, and Workers; permission to create a WAF custom rule; a Worker deployed on a route for the lab hostname. Cache Rules and WAF custom rules exist on all plans with plan-dependent quotas, while some Origin Rule overrides are Enterprise-only — confirm your plan before including them.
Setup. Use a dedicated hostname such as lab.example.com and one Worker that echoes each request as JSON: method, URL, host header, and any lab-prefixed headers. Create an origin path that returns a distinctive header so you can tell which backend answered.
Rules to create, in this order.
- Single Redirect: when
http.request.uri.path eq "/lab/start", redirect 302 to/lab/final, preserving the query string. - URL Rewrite: when
starts_with(http.request.uri.path, "/lab/old/"), rewrite the path by replacing/lab/old/with/lab/new/. - WAF custom rule: block when
http.request.uri.path contains "/lab/new/admin". - Cache Rule: when
starts_with(http.request.uri.path, "/lab/new/"), eligible for cache with a 60-second edge TTL. - Origin Rule (optional, Enterprise for host override): when
starts_with(http.request.uri.path, "/lab/old/"), rewrite the host tolegacy.example.net.
Action: predict before you send. Write down the expected status code, final URL, cache status, and receiving origin for each probe, then send it and compare.
| Probe | What to predict | What it tests |
|---|---|---|
GET /lab/start?ref=email | Which wins: redirect or rewrite | Phase order between redirect and transform |
GET /lab/old/page | What the WAF sees, and whether the Origin Rule still matches | Snapshot propagation into later phases |
GET /lab/old/admin | Whether the block fires before or after the rewrite | WAF phase placement |
GET /lab/new/page, twice inside 60 seconds | The cache status on each response | Cache key built from the post-rewrite path |
GET /lab/old/page with a cookie set | Whether the cache rule still applies | Cookie handling in cache eligibility |
Expected observations.
- Probe 1: a 302 to
/lab/final; the Worker never runs, because the redirect phase precedes the transform phase. - Probe 2: the page renders, but later phases see
/lab/new/page. The Origin Rule does not fire because it tests the pre-rewrite path; check the Worker's echoed URL to confirm what it saw. - Probe 3: a block, because WAF custom rules run after the rewrite phase.
- Probe 4: a miss then a hit, since the cache key is built from the post-rewrite path.
- Probe 5: depends entirely on the cache rule's cookie handling. If the expression ignores cookies while the origin varies on them, you have reproduced the personalization leak from the cache-rules article.
Failure checks. If probe 1 reaches the Worker, the redirect rule's expression is wrong or the rule is disabled. If probe 3 returns 200, either the WAF expression tests the old path or the rule sits in a phase that never runs for that hostname. If probe 2 hits the legacy origin, the Origin Rule is matching when you expected it to skip — check whether you used raw.http.request.uri.path. If probe 4 never hits, confirm the response is actually cacheable and that no later cache rule sets bypass.
Cost. One Worker request per probe, a handful of rule evaluations, and negligible bandwidth. Cache storage for one small object for 60 seconds. No paid add-on is required for the core trace.
Cleanup. Delete all five rules, remove the Worker route, delete the Worker, and purge the lab hostname's cache so the 60-second object does not outlive the exercise.
Predict and Verify the Final URL, Headers, and Origin
Verification for this article was performed against Cloudflare's documentation on 2026-11-05, with a planning baseline of 2026-11-02. No hosted lab was executed: the editorial record for this topic is lab_status: not_run, and every behavioral statement below is a documentation-derived expectation rather than a measurement.
Pass criteria for the method. A trace is trustworthy when all of the following hold. It fails if any one does not.
- Pass: the predicted final URL is stated before the request is sent, including scheme, host, path, and query string.
- Pass: each rule that matched is named together with its phase, and each rule that did not match has a stated reason — no match, skipped, terminated earlier, or overridden later.
- Pass: the receiving origin and the
Hostheader it saw are both recorded, not just the status code. - Fail: the explanation is "the rule did not fire" with no phase assigned to it.
- Fail: a redirect and a rewrite are described as if they compose. A redirect ends the request; the browser starts a new one.
- Fail: cache behavior is inferred from the URL alone without checking
cf-cache-statusandage.
Self-check. Answer before reading the explanations.
- A Single Redirect and a URL Rewrite both match
/promo. Which runs, and does the other still apply? - Two Cache Rules match the same path. Rule A sets a one-day edge TTL; rule B, placed later, sets bypass. What happens?
- A custom rule blocking
/internal/loginno longer fires after a rewrite ships, and a rule blocking/public-loginstarts firing. Why?
- The redirect runs, in
http_request_dynamic_redirect, and the request ends with a 3xx. The rewrite never executes for that request; the browser's follow-up request is a new request and may then match the rewrite if its path does. Redirect and rewrite are alternatives in sequence, not layers. - Cache is bypassed. Both rules are non-terminating, both match, and for conflicting settings the last matching rule wins. The one-day TTL from rule A is overridden, not merged into a compromise.
- The rewrite phase runs before WAF custom rules, so the path the WAF evaluates changed. The
/internal/loginrule now sees a path that no longer matches, and the/public-loginrule sees the rewritten path that visitors never typed. Either rewrite the WAF expressions or move both toraw.http.request.uri.path.
Unresolved limitations. Rules simulator is Beta and omits automatic operational bypasses, so a clean simulation is not proof that a rule will fire in production. Plan-gated features — regular-expression matches, Origin Rule host/SNI/DNS overrides, account-level phases — could not be exercised without an entitled zone. Page Rules migration status is documented as planned rather than complete, and the exact timing may have changed since the cited revision. Worker visibility of a rewritten path was not verified in a hosted environment and should be confirmed in your own trace before it is relied on. Finally, no latency or cache-hit-rate numbers are claimed here; those require measurement on real traffic.
Authoritative references.
- Cloudflare Rules overview — https://developers.cloudflare.com/rules/
- Ruleset Engine: Phases — https://developers.cloudflare.com/ruleset-engine/about/phases/
- Ruleset Engine: Phases list (execution order) — https://developers.cloudflare.com/ruleset-engine/reference/phases-list/
- Ruleset Engine: Rules and field values during evaluation — https://developers.cloudflare.com/ruleset-engine/about/rules/
- Ruleset Engine: Actions, including terminating and skip semantics — https://developers.cloudflare.com/ruleset-engine/rules-language/actions/
- Page Rules migration guide — https://developers.cloudflare.com/rules/reference/page-rules-migration/
- Cache Rules: Migration from Page Rules — https://developers.cloudflare.com/cache/how-to/cache-rules/page-rules-migration/
- Cache Rules: Order and priority — https://developers.cloudflare.com/cache/how-to/cache-rules/order/
- WAF: Rule phase interactions — https://developers.cloudflare.com/waf/troubleshooting/phase-interactions/
- Rules: Troubleshoot Rules (rewrites, challenges, DCV paths) — https://developers.cloudflare.com/rules/reference/troubleshooting/
- Rules simulator — https://developers.cloudflare.com/rules/simulator/
- Rules simulator limitations — https://developers.cloudflare.com/rules/simulator/limitations/
- Cache and Workers interaction — https://developers.cloudflare.com/cache/interaction-cloudflare-products/workers/