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.
-
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 If incoming requests match, select one of the following options:
-
Wildcard pattern: The rule will only apply to traffic matching the wildcard pattern in Request URL. Refer to Wildcard pattern parameters for details.
-
Custom filter expression: The rule will only apply to traffic matching a custom expression. Define the rule expression to configure which requests should be rewritten. Use either the Expression Builder or the Expression Editor to define the custom expression. For more information, refer to Edit expressions in the dashboard.
-
All incoming requests: The rule will apply to all traffic.
-
-
(Optional) Define the action for your rewrite URL rule by selecting one of the available options displayed as radio buttons, and then a value from the drop-down list, depending on the action:
-
If you select Rewrite to > Static, enter the string that will replace the original URL path (or query string). For example, enter
welcome-gb.html
to rewrite the original URL path to/welcome-gb.html
. -
If you select Rewrite to > Dynamic, enter a rewrite expression that defines the dynamic URL rewrite to perform.
-
If you do not want to change the value of a component of the original request (the URL path or the URL query string), choose the Preserve action for that component.
For more information, refer to URL rewrite parameters.
-
-
Under Place at, define where to place the rule in the rules list: first rule in the list, last rule in the list, or in a custom position (after a given rule).
-
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 rewrite URL rule, the new rule will be enabled. If you save the rule as a draft, the new rule will be disabled.
The Cloudflare dashboard offers a simplified user interface for creating URL rewrites based on wildcard matching and replacement. When you select Wildcard pattern, you will have the following parameters available:
-
Request URL: Enter the wildcard pattern using the asterisk (
*
) character to match multiple requests. For example,http*://*.example.com/*
. -
Then rewrite the path and/or query: Define the URL rewrite settings including:
- Path > Target path: Enter the URI path to match, which can include wildcards (for example,
/oldpath/*
). - Path > Rewrite to: Enter the new URI path. You can use wildcard replacement such as
${1}
and${2}
to define a dynamic target path (for example,/newpath/${1}
). Leave this field empty to remove the URI path. - Query > Target query: Enter the query string to match, which can include wildcards (for example,
?sort=*
). - Query > Rewrite to: Enter the new query string. You can use wildcard replacement such as
${1}
and${2}
to define a dynamic query string (for example,?order=${1}
). Leave this field empty to remove the query string.
- Path > Target path: Enter the URI path to match, which can include wildcards (for example,
Refer to URL rewrite parameters for the equivalent rule configuration when using the API.