Use the Rulesets API to create URL Rewrite Rules via API. Refer to the Rules examples gallery for common use cases.
If you are using Terraform, refer to Transform Rules configuration using Terraform.
When creating a URL rewrite rule via API, make sure you:
- Set the rule action to
rewrite. - Define the URL rewrite parameters in the
action_parametersfield according to the type of URL rewrite (static or dynamic). - Deploy the rule to the
http_request_transformphase at the zone level.
Follow this workflow to create a URL rewrite rule for a given zone via API:
-
Use the List zone rulesets operation to check if there is already a ruleset for the
http_request_transformphase at the zone level. -
If the phase ruleset does not exist, create it using the Create a zone ruleset operation. In the new ruleset properties, set the following values:
- kind:
zone - phase:
http_request_transform
- kind:
-
Use the Update a zone ruleset operation to add a URL rewrite rule to the list of ruleset rules. Alternatively, include the rule in the Create a zone ruleset request mentioned in the previous step.
Make sure your API token has the required permissions to perform the API operations.