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.
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: 1Spec
What you set, with the limits the API server enforces.
| Field | Description |
|---|---|
descriptionstring | Description is shown with the rule in the Cloudflare dashboard. Limits: at most 4096 characters |
enabledboolean | Enabled turns the rule on or off without deleting it. Default: |
expressionstringrequired | Expression selects the requests the rule applies to, in Cloudflare's Rules language, for example Limits: 1 to 4096 characters |
fromValueobjectrequired | FromValue redirects the requests the rule matches to a URL: targetURL's, with statusCode. |
fromValue.preserveQueryStringboolean | PreserveQueryString keeps the request's query string on the URL redirected to. Unset, the query string is dropped. |
fromValue.statusCodeinteger | 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: Limits: format |
fromValue.targetURLobjectrequired | 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.expressionstring | Expression computes the URL in Cloudflare's Rules language, such as Limits: at least 1 character |
fromValue.targetURL.valuestring | Value is a static URL, such as Limits: at least 1 character |
priorityinteger | 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 |
zoneRefobjectrequiredimmutable | ZoneRef references the Zone, in the same namespace, the rule belongs to. Immutable after creation. |
zoneRef.namestring | 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.
| Field | Description |
|---|---|
cloudflareMetadataobject | CloudflareMetadata identifies the rule in Cloudflare. |
cloudflareMetadata.refstring | 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.ruleIDstring | RuleID is the rule's Cloudflare ID. |
cloudflareMetadata.rulesetIDstring | RulesetID is the zone's entry point ruleset for the rule's phase. |
cloudflareMetadata.versionstring | Version is the rule's version, which Cloudflare increments whenever the rule changes. |
cloudflareMetadata.zoneIDstring | 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.
| Column | Source |
|---|---|
| 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.
# 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