Many Cloudflare products work the same way: you write a rule that says "when a request looks like this, do that." Redirect Rules, Transform Rules, Cache Rules, Configuration Rules, and WAF custom rules all follow this model.
The Ruleset Engine is the shared system behind these products. All of them use the same Rules language and the same API. After you learn to write a rule for one product, you can write rules for the others.
In the Cloudflare dashboard, you usually create rules only. For most products, Cloudflare manages rulesets and phases for you.
The Ruleset Engine uses the following concepts:
| Concept | What it is | Example |
|---|---|---|
| Rule | An expression plus an action. | When the path starts with /old/, redirect to /new/. |
| Expression | The condition that selects which requests a rule applies to. You write it in the Rules language, or build it from drop-down menus in the dashboard. | http.request.uri.path wildcard "/old/*" |
| Action | What happens when the expression matches a request. | Redirect, rewrite, set a header, cache, or block. |
| Ruleset | An ordered list of rules. Each product stores its rules in a ruleset. | All redirect rules for a zone. |
| Phase | A point in the request life cycle where rulesets run. Phases always run in the same order. | Redirect Rules (Single Redirects) run before Cache Rules. |
For more information, refer to About Ruleset Engine.
- A request arrives at Cloudflare.
- Cloudflare runs each phase in a fixed order. Refer to the Phases list for the full order.
- Within a phase, Cloudflare checks rules in the order you define them.
- When an expression matches, Cloudflare runs the rule's action.
Terminating actions, such as Redirect, Block, or a challenge, stop rule evaluation, and Cloudflare responds immediately. The remaining rules in the phase and later request phases do not run for that request. Response phases can still apply to the response that Cloudflare generates. For example, Response Header Transform Rules apply to redirect responses, and Custom Error Rules apply to the error response of a Block action.
Non-terminating actions, such as setting a header, do not stop evaluation. If several rules in the same phase change the same value, the last rule wins. Refer to Actions for details.
Use the following table to find documentation for your task:
| Goal | Refer to |
|---|---|
| Redirect URLs | Redirects |
| Rewrite URLs or modify headers | Transform Rules |
| Control caching | Cache Rules |
| Adjust settings for some requests | Configuration Rules |
| Block or challenge traffic | WAF custom rules |
| Migrate from Page Rules | Page Rules migration guide |
| Learn to write expressions | Rules language |
| Configure rules with the API | Rulesets API |
Each product built on the Ruleset Engine has its own quotas and plan availability. Some features, such as regular expressions, depend on your plan. Refer to each product's documentation for details.