Skip to content
Documentation menu

Docs / Reference / Rules

RedirectRule

RedirectRule manages one single redirect in a zone: Cloudflare answers the requests its expression matches with a redirect to a URL, a static one or one an expression computes.

API version
kflare.dev/v1alpha1
Scope
Namespaced
Short name
cfredirect
Token permission
Zone · Single Redirect · Edit

Example

Every field, with the sample's values. The live lines are the repository's sample, which applies as it is; the commented ones are the other fields, filled from other samples where one sets them. Some exclude each other, so check the rules before you uncomment several.

redirectrule.yaml
apiVersion: kflare.dev/v1alpha1
kind: RedirectRule
metadata:
  name: example-redirectrule
  namespace: default
spec:
  zoneRef:
    name: example-zone
  expression: http.host eq "www.example.com"
  description: Send www.example.com to example.com, keeping the path and query
  fromValue:
    targetURL:
      expression: concat("https://example.com", http.request.uri.path)
      # value: <value>
    preserveQueryString: true
    statusCode: 301
  # enabled: true
  # priority: 1

Spec

What you set, with the limits the API server enforces.

FieldDescription
description
string

Description is shown with the rule in the Cloudflare dashboard.

Limits: at most 4096 characters

enabled
boolean

Enabled turns the rule on or off without deleting it.

Default: true

expression
stringrequired

Expression selects the requests the rule applies to, in Cloudflare's Rules language, for example http.request.uri.path eq "/admin". Cloudflare validates it; the fields and operators it may use depend on the zone's plan.

Limits: 1 to 4096 characters

fromValue
objectrequired

FromValue redirects the requests the rule matches to a URL: targetURL's, with statusCode.

fromValue.preserveQueryString
boolean

PreserveQueryString keeps the request's query string on the URL redirected to. Unset, the query string is dropped.

fromValue.statusCode
integer

StatusCode is the redirect's status: 301 or 308 for a permanent redirect, 302, 303 or 307 for a temporary one. Unset, Cloudflare redirects with 301.

One of: 301, 302, 303, 307, 308

Limits: format int64

fromValue.targetURL
objectrequired

TargetURL is the URL requests are redirected to: a static value, or what an expression computes for each request.

Rule: must set exactly one of expression and value

fromValue.targetURL.expression
string

Expression computes the URL in Cloudflare's Rules language, such as concat("https://example.com", http.request.uri.path). Free plans cannot use regex_replace; wildcard_replace works on every plan.

Limits: at least 1 character

fromValue.targetURL.value
string

Value is a static URL, such as https://example.com/new. Cloudflare takes it as given, a relative URL too.

Limits: at least 1 character

priority
integer

Priority orders the rules kflare manages in a zone and phase: lower runs first, and rules with the same priority run in order of namespace and name. Rules created outside kflare keep their place.

Limits: format int32

zoneRef
objectrequiredimmutable

ZoneRef references the Zone, in the same namespace, the rule belongs to. Immutable after creation.

zoneRef.name
string

Name of the referent. This field is effectively required, but due to backwards compatibility is allowed to be empty. Instances of this type with an empty value here are almost certainly wrong. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names

Default: ""

Status

What kflare reports. conditions holds the Ready condition, whose reason says why a resource isn't ready.

FieldDescription
cloudflareMetadata
object

CloudflareMetadata identifies the rule in Cloudflare.

cloudflareMetadata.ref
string

Ref is the rule's ref, which kflare derives from the resource's kind, namespace and name. kflare finds the rule it manages by its ref.

cloudflareMetadata.ruleID
string

RuleID is the rule's Cloudflare ID.

cloudflareMetadata.rulesetID
string

RulesetID is the zone's entry point ruleset for the rule's phase.

cloudflareMetadata.version
string

Version is the rule's version, which Cloudflare increments whenever the rule changes.

cloudflareMetadata.zoneID
string

ZoneID is the Cloudflare zone the rule is in.

conditions
[]object

Conditions represent the latest available observations of the rule's state.

kubectl get

The columns kubectl get redirectrules prints.

ColumnSource
PRIORITY.spec.priority
RULE ID.status.cloudflareMetadata.ruleID
READY.status.conditions[?(@.type=="Ready")].status
AGE.metadata.creationTimestamp

Samples

From the repository's config/samples, comments included.

cloudflare_v1alpha1_redirectrule.yaml
# Generated by kflare-gen from generator/generator.yaml. DO NOT EDIT.
#
# RedirectRule is the Schema for the redirectrules API.
# It manages one single redirect in a zone: Cloudflare answers the requests
# its expression matches with a redirect to a URL, a static one or one an
# expression computes.
apiVersion: kflare.dev/v1alpha1
kind: RedirectRule
metadata:
  name: example-redirectrule
  namespace: default
spec:
  zoneRef:
    name: example-zone
  expression: http.host eq "www.example.com"
  description: Send www.example.com to example.com, keeping the path and query
  fromValue:
    targetURL:
      expression: concat("https://example.com", http.request.uri.path)
    preserveQueryString: true
    statusCode: 301

On GitHub