Create a rule in the dashboard
Refer to the Rules examples gallery for examples of rule definitions.
To create a rule:
-
Log in to the Cloudflare dashboard ↗, and select your account and website.
-
Go to Rules > Transform Rules.
-
Go to the Modify Request Header tab.
-
To create a new empty rule, select Create rule. To duplicate an existing rule, select the three dots next to it > Duplicate.
-
In the rule creation page, enter a descriptive name for the rule in Rule name.
-
Under When incoming requests match, select if you wish to apply the rule to all incoming requests or only to requests that match a custom filter expression.
-
(Optional) To define a custom expression, use the Expression Builder (specifying one or more values for Field, Operator, and Value) or manually enter an expression using the Expression Editor. For more information, refer to Edit expressions in the dashboard.
-
For Modify request header, select one of the following options:
- Set static — Sets the value of an HTTP request header to a static string value. Overrides the value of an existing header with the same name or adds a new header if it does not exist.
- Set dynamic — Sets the value of an HTTP request header according to the provided expression. Overrides the value of an existing header with the same name or adds a new header if it does not exist.
- Remove — Removes the HTTP request header with the provided name, if it exists.
-
Enter the name of the HTTP request header to modify in Header name and the static value or expression in Value, if you are setting the header value.
-
To modify another HTTP request header in the same rule, select Set new header. You can modify up to 30 HTTP request headers in a single rule.
The following example includes the modification of three headers:
-
To save and deploy your rule, select Deploy. If you are not ready to deploy your rule, select Save as Draft.
If you choose to deploy your HTTP request header modification rule, the new rule will be enabled. If you save the rule as a draft, the new rule will be disabled.