| [ Web Proxy ] |
| Viewing: https://developers.cloudflare.com/rules/origin-rules/ | [Back] [Original] |
Origin Rules allow you to change the origin server that Cloudflare sends a request to, or modify how the request reaches that server. This is useful when you need to route specific requests to a different backend, such as a third-party service or a server on a non-standard port. You can perform the following overrides:
Host header of incoming requests.Each origin rule includes a filter expression that defines which requests the overrides apply to (for example, matching on hostname, path, or other request properties).
For more complex and customized modifications, consider using Snippets.
Note
Origin Rules require that you proxy the DNS records of your domain (or subdomain) through Cloudflare.
Cloudflare provides you with rules templates for common use cases.
In the Cloudflare dashboard, go to the Rules Overview page.
Go to Overview ↗Select Templates, and then select one of the available templates.
You can also refer to the Examples gallery in the developer docs.
| Free | Pro | Business | Enterprise | |
|---|---|---|---|---|
| Availability | Yes | Yes | Yes | Yes |
| Number of rules | 10 | 25 | 50 | 300 |
| Override Host header | No | No | No | Yes |
| Override SNI | No | No | No | Yes |
| Override DNS records | No | No | No | Yes |
| Override destination port | Yes | Yes | Yes | Yes |
The execution order of Rules features is the following:
The different types of rules listed above will take precedence over Page Rules. This means that Page Rules will be overridden if there is a match for both Page Rules and the Rules products listed above.
Generally speaking, for non-terminating actions the last change made by rules in the same phase will win (later rules can overwrite changes done by previous rules). However, for terminating actions (Block, Redirect, or one of the challenge actions), rule evaluation will stop and the action will be executed immediately.
For example, if multiple rules with the Redirect action match, Cloudflare will always use the URL redirect of the first rule that matches. Also, if you configure URL redirects using different Cloudflare products (Single Redirects and Bulk Redirects), the product executed first will apply, if there is a rule match (in this case, Single Redirects).
Refer to the Phases list for the product execution order.
Caution
Using Cloudflare challenges along with Rules features may cause challenge loops. Refer to Rules troubleshooting for more information.
If you override the hostname with an origin rule (via Host header override or DNS record override) and add a header override to your load balancer configuration, the origin rule will take precedence over the load balancer configuration.
Like Page Rules, an origin rule performing a Host header override will update the SNI value of the original request to the same value of the Host header. To set an SNI value different from the Host header override, add an SNI override in the same origin rule or create a separate origin rule for this purpose.
When troubleshooting origin rules, use Cloudflare Trace to determine if a rule is triggering for a specific URL.
| Web Proxy Viewer | New URL | Original Page |