Cloudflare Docs
Rules
Rules
Edit this page
Give us feedback
Set theme to dark (⇧+D)

Create a redirect rule using Terraform

The following example defines a single redirect rule for a zone using Terraform. The rule creates a static URL redirect for visitors requesting the contacts page using an old URL.

# Single Redirects resource
resource "cloudflare_ruleset" "single_redirects_example" {
zone_id = "<ZONE_ID>"
name = "redirects"
description = "Redirects ruleset"
kind = "zone"
phase = "http_request_dynamic_redirect"
rules {
action = "redirect"
action_parameters {
from_value {
status_code = 301
target_url {
value = "/contacts/"
}
preserve_query_string = false
}
}
expression = "(http.request.uri.path matches \"^/contact-us/\")"
description = "Redirect visitors still using old URL"
enabled = true
}
}

​​ Additional resources

For additional guidance on using Terraform with Cloudflare, refer to the following resources: