Cloudflare 中文文档
Rules
Rules
编辑这个页面
跳转官方原文档
Set theme to dark (⇧+D)

Create a redirect rule via API

Use the Rulesets API to create a redirect rule via API.

Add redirect rules to the entry point ruleset of the http_request_dynamic_redirect phase at the zone level. Refer to the Rulesets API documentation for more information on creating a ruleset and supplying a list of rules for the ruleset.

​​ Basic rule settings

A redirect rule must have:

  • action set to redirect
  • An action_parameters object with additional configuration settings — refer to Available settings for details.

​​ Example requests

The following request of the Create a zone ruleset operation creates a phase entry point ruleset for the http_request_dynamic_redirect phase at the zone level, and defines a single redirect rule with a dynamic URL redirect. Use this operation if you have not created a phase entry point ruleset for the http_request_dynamic_redirect phase yet.

Response

If there is already a phase entry point ruleset for the http_request_dynamic_redirect phase, use the Update a zone ruleset operation instead, like in the following example:

Response

​​ Required API token permissions

The API token used in API requests to manage redirect rules must have at least the following permission:

  • Zone > Dynamic Redirect > Edit