Fetches Page Rules in a zone.
Security
API Token
The preferred authorization scheme for interacting with the Cloudflare API. Create a token.
Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYYAPI Email + API Key
The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.
X-Auth-Email: user@example.comThe previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.
X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194Accepted Permissions (at least one required)
Zone ReadZone WritePage Rules WritePage Rules ReadParametersExpand Collapse
params PageRuleListParams
ReturnsExpand Collapse
Actions []PageRuleActionThe set of actions to perform if the targets of this rule match the
request. Actions can redirect to another URL or override settings, but
not both.
The set of actions to perform if the targets of this rule match the request. Actions can redirect to another URL or override settings, but not both.
type BrowserCheck struct{…}
type PageRuleActionsBypassCacheOnCookie struct{…}
Bypass cache and fetch resources from the origin server if a regular expression matches against a cookie name present in the request.
The regular expression to use for matching cookie names in the request. Refer to Bypass Cache on Cookie setting to learn about limited regular expression support.
type PageRuleActionsCacheByDeviceType struct{…}
type PageRuleActionsCacheDeceptionArmor struct{…}
Protect from web cache deception attacks while still allowing static
assets to be cached. This setting verifies that the URL's extension
matches the returned Content-Type.
type PageRuleActionsCacheKeyFields struct{…}
Control specifically what variables to include when deciding which resources to cache. This allows customers to determine what to cache based on something other than just the URL.
Value PageRuleActionsCacheKeyFieldsValueoptional
Cookie PageRuleActionsCacheKeyFieldsValueCookieoptionalControls which cookies appear in the Cache Key.
Controls which cookies appear in the Cache Key.
Header PageRuleActionsCacheKeyFieldsValueHeaderoptionalControls which headers go into the Cache Key. Exactly one of
include or exclude is expected.
Controls which headers go into the Cache Key. Exactly one of
include or exclude is expected.
Host PageRuleActionsCacheKeyFieldsValueHostoptionalDetermines which host header to include in the Cache Key.
Determines which host header to include in the Cache Key.
QueryString PageRuleActionsCacheKeyFieldsValueQueryStringoptionalControls which URL query string parameters go into the Cache
Key. Exactly one of include or exclude is expected.
Controls which URL query string parameters go into the Cache
Key. Exactly one of include or exclude is expected.
type CacheLevel struct{…}
Value CacheLevelValueoptional
bypass: Cloudflare does not cache.
basic: Delivers resources from cache when there is no query
string.
simplified: Delivers the same resource to everyone independent
of the query string.
aggressive: Caches all static content that has a query string.
cache_everything: Treats all content as static and caches all
file types beyond the Cloudflare default cached
content.
bypass: Cloudflare does not cache.basic: Delivers resources from cache when there is no query string.simplified: Delivers the same resource to everyone independent of the query string.aggressive: Caches all static content that has a query string.cache_everything: Treats all content as static and caches all file types beyond the Cloudflare default cached content.
type PageRuleActionsCacheTTLByStatus struct{…}
Enterprise customers can set cache time-to-live (TTL) based on the
response status from the origin web server. Cache TTL refers to the
duration of a resource in the Cloudflare network before being
marked as stale or discarded from cache. Status codes are returned
by a resource's origin. Setting cache TTL based on response status
overrides the default cache behavior (standard caching) for static
files and overrides cache instructions sent by the origin web
server. To cache non-static assets, set a Cache Level of Cache
Everything using a Page Rule. Setting no-store Cache-Control or a
low TTL (using max-age/s-maxage) increases requests to origin
web servers and decreases performance.
Value map[string, PageRuleActionsCacheTTLByStatusValueUnion]optionalA JSON object containing status codes and their corresponding TTLs.
Each key-value pair in the cache TTL by status cache rule has the
following syntax
status_code: An integer value such as 200 or 500. status_code
matches the exact status code from the origin web server. Valid
status codes are between 100-999.
status_code_range: Integer values for from and to.
status_code_range matches any status code from the origin web
server within the specified range.
value: An integer value that defines the duration an asset is
valid in seconds or one of the following strings: no-store
(equivalent to -1), no-cache (equivalent to 0).
A JSON object containing status codes and their corresponding TTLs. Each key-value pair in the cache TTL by status cache rule has the following syntax
status_code: An integer value such as 200 or 500. status_code matches the exact status code from the origin web server. Valid status codes are between 100-999.status_code_range: Integer values for from and to. status_code_range matches any status code from the origin web server within the specified range.value: An integer value that defines the duration an asset is valid in seconds or one of the following strings: no-store (equivalent to -1), no-cache (equivalent to 0).
type PageRuleActionsDisableApps struct{…}
Turn off all active Cloudflare Apps (deprecated).
type PageRuleActionsDisablePerformance struct{…}
Turn off Rocket Loader, and Polish.
type PageRuleActionsDisableZaraz struct{…}
Turn off Zaraz.
type PageRuleActionsExplicitCacheControl struct{…}
type PageRuleActionsForwardingURL struct{…}
Redirects one URL to another using an HTTP 301/302 redirect. Refer
to Wildcard matching and referencing.
type IPGeolocation struct{…}
type Mirage struct{…}
type OpportunisticEncryption struct{…}
type OriginErrorPagePassThru struct{…}
type PageRuleActionsRespectStrongEtag struct{…}
type ResponseBuffering struct{…}
type SortQueryStringForCache struct{…}
type SSL struct{…}
type TrueClientIPHeader struct{…}
type WAF struct{…}
Turn on or off WAF managed rules (previous version, deprecated). You cannot enable or disable individual WAF managed rules via Page Rules.
The priority of the rule, used to define which Page Rule is processed
over another. A higher number indicates a higher priority. For example,
if you have a catch-all Page Rule (rule A: /images/*) but want a more
specific Page Rule to take precedence (rule B: /images/special/*),
specify a higher priority for rule B so it overrides rule A.
Targets []TargetThe rule targets to evaluate on each request.
The rule targets to evaluate on each request.
List Page Rules
package main
import (
"context"
"fmt"
"github.com/cloudflare/cloudflare-go"
"github.com/cloudflare/cloudflare-go/option"
"github.com/cloudflare/cloudflare-go/page_rules"
)
func main() {
client := cloudflare.NewClient(
option.WithAPIToken("Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY"),
)
pageRules, err := client.PageRules.List(context.TODO(), page_rules.PageRuleListParams{
ZoneID: cloudflare.F("023e105f4ecef8ad9ca31a8372d0c353"),
})
if err != nil {
panic(err.Error())
}
fmt.Printf("%+v\n", pageRules)
}
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"success": true,
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"actions": [
{
"id": "browser_check",
"value": "on"
}
],
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"priority": 0,
"status": "active",
"targets": [
{
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
},
"target": "url"
}
]
}
]
}Returns Examples
{
"errors": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"messages": [
{
"code": 1000,
"message": "message",
"documentation_url": "documentation_url",
"source": {
"pointer": "pointer"
}
}
],
"success": true,
"result": [
{
"id": "023e105f4ecef8ad9ca31a8372d0c353",
"actions": [
{
"id": "browser_check",
"value": "on"
}
],
"created_on": "2014-01-01T05:20:00.12345Z",
"modified_on": "2014-01-01T05:20:00.12345Z",
"priority": 0,
"status": "active",
"targets": [
{
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
},
"target": "url"
}
]
}
]
}