Skip to content
Start here

List Page Rules

client.PageRules.List(ctx, params) (*[]PageRule, error)
GET/zones/{zone_id}/pagerules

Fetches Page Rules in a zone.

Security
API Token

The preferred authorization scheme for interacting with the Cloudflare API. Create a token.

Example:Authorization: Bearer Sn3lZJTBX6kkg7OdcBUAxOO963GEIyGQqnFTOFYY
API Email + API Key

The previous authorization scheme for interacting with the Cloudflare API, used in conjunction with a Global API key.

Example:X-Auth-Email: user@example.com

The previous authorization scheme for interacting with the Cloudflare API. When possible, use API tokens instead of Global API keys.

Example:X-Auth-Key: 144c9defac04969c7bfad8efaa8ea194
Accepted Permissions (at least one required)
Zone ReadZone WritePage Rules WritePage Rules Read
ParametersExpand Collapse
params PageRuleListParams
ZoneID param.Field[string]

Path param: Identifier.

maxLength32
Direction param.Field[PageRuleListParamsDirection]optional

Query param: The direction used to sort returned Page Rules.

const PageRuleListParamsDirectionAsc PageRuleListParamsDirection = "asc"
const PageRuleListParamsDirectionDesc PageRuleListParamsDirection = "desc"
Match param.Field[PageRuleListParamsMatch]optional

Query param: When set to all, all the search requirements must match. When set to any, only one of the search requirements has to match.

const PageRuleListParamsMatchAny PageRuleListParamsMatch = "any"
const PageRuleListParamsMatchAll PageRuleListParamsMatch = "all"
Order param.Field[PageRuleListParamsOrder]optional

Query param: The field used to sort returned Page Rules.

const PageRuleListParamsOrderStatus PageRuleListParamsOrder = "status"
const PageRuleListParamsOrderPriority PageRuleListParamsOrder = "priority"
Status param.Field[PageRuleListParamsStatus]optional

Query param: The status of the Page Rule.

const PageRuleListParamsStatusActive PageRuleListParamsStatus = "active"
const PageRuleListParamsStatusDisabled PageRuleListParamsStatus = "disabled"
ReturnsExpand Collapse
type PageRuleListResponseEnvelopeResult []PageRule
ID string

Identifier.

maxLength32
Actions []PageRuleAction

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.

One of the following:
type AlwaysUseHTTPS struct{…}
ID AlwaysUseHTTPSIDoptional

If enabled, any http://`` URL is converted to https://` through a 301 redirect.

type AutomaticHTTPSRewrites struct{…}
ID AutomaticHTTPSRewritesIDoptional

Turn on or off Automatic HTTPS Rewrites.

Value AutomaticHTTPSRewritesValueoptional

The status of Automatic HTTPS Rewrites.

One of the following:
const AutomaticHTTPSRewritesValueOn AutomaticHTTPSRewritesValue = "on"
const AutomaticHTTPSRewritesValueOff AutomaticHTTPSRewritesValue = "off"
type BrowserCacheTTL struct{…}
ID BrowserCacheTTLIDoptional

Control how long resources cached by client browsers remain valid.

Value int64optional

The number of seconds to cache resources for. Setting this to 0 enables "Respect Existing Headers".

maximum31536000
minimum0
type BrowserCheck struct{…}
ID BrowserCheckIDoptional

Inspect the visitor's browser for headers commonly associated with spammers and certain bots.

Value BrowserCheckValueoptional

The status of Browser Integrity Check.

One of the following:
const BrowserCheckValueOn BrowserCheckValue = "on"
const BrowserCheckValueOff BrowserCheckValue = "off"
type PageRuleActionsBypassCacheOnCookie struct{…}
ID PageRuleActionsBypassCacheOnCookieIDoptional

Bypass cache and fetch resources from the origin server if a regular expression matches against a cookie name present in the request.

Value stringoptional

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.

maxLength150
minLength1
type PageRuleActionsCacheByDeviceType struct{…}
ID PageRuleActionsCacheByDeviceTypeIDoptional

Separate cached content based on the visitor's device type.

Value PageRuleActionsCacheByDeviceTypeValueoptional

The status of Cache By Device Type.

One of the following:
const PageRuleActionsCacheByDeviceTypeValueOn PageRuleActionsCacheByDeviceTypeValue = "on"
const PageRuleActionsCacheByDeviceTypeValueOff PageRuleActionsCacheByDeviceTypeValue = "off"
type PageRuleActionsCacheDeceptionArmor struct{…}
ID PageRuleActionsCacheDeceptionArmorIDoptional

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.

Value PageRuleActionsCacheDeceptionArmorValueoptional

The status of Cache Deception Armor.

One of the following:
const PageRuleActionsCacheDeceptionArmorValueOn PageRuleActionsCacheDeceptionArmorValue = "on"
const PageRuleActionsCacheDeceptionArmorValueOff PageRuleActionsCacheDeceptionArmorValue = "off"
type PageRuleActionsCacheKeyFields struct{…}
ID PageRuleActionsCacheKeyFieldsIDoptional

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
Header PageRuleActionsCacheKeyFieldsValueHeaderoptional

Controls which headers go into the Cache Key. Exactly one of include or exclude is expected.

CheckPresence []stringoptional

A list of headers to check for the presence of, without including their actual values.

Exclude []stringoptional

A list of headers to ignore.

Include []stringoptional

A list of headers to include.

Host PageRuleActionsCacheKeyFieldsValueHostoptional

Determines which host header to include in the Cache Key.

Resolved booloptional

Whether to include the Host header in the HTTP request sent to the origin.

QueryString PageRuleActionsCacheKeyFieldsValueQueryStringoptional

Controls which URL query string parameters go into the Cache Key. Exactly one of include or exclude is expected.

Exclude PageRuleActionsCacheKeyFieldsValueQueryStringExcludeUnionoptional

Ignore all query string parameters.

One of the following:
type PageRuleActionsCacheKeyFieldsValueQueryStringExcludeString string

Ignore all query string parameters.

type PageRuleActionsCacheKeyFieldsValueQueryStringExcludeArray []string

A list of query string parameters to ignore.

Include PageRuleActionsCacheKeyFieldsValueQueryStringIncludeUnionoptional

Include all query string parameters.

One of the following:
type PageRuleActionsCacheKeyFieldsValueQueryStringIncludeString string

Include all query string parameters.

type PageRuleActionsCacheKeyFieldsValueQueryStringIncludeArray []string

A list of query string parameters to include.

User PageRuleActionsCacheKeyFieldsValueUseroptional

Feature fields to add features about the end-user (client) into the Cache Key.

DeviceType booloptional

Classifies a request as mobile, desktop, or tablet based on the User Agent.

Geo booloptional

Includes the client's country, derived from the IP address.

Lang booloptional

Includes the first language code contained in the Accept-Language header sent by the client.

type CacheLevel struct{…}
ID CacheLevelIDoptional

Apply custom caching based on the option selected.

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.
One of the following:
const CacheLevelValueBypass CacheLevelValue = "bypass"
const CacheLevelValueBasic CacheLevelValue = "basic"
const CacheLevelValueSimplified CacheLevelValue = "simplified"
const CacheLevelValueAggressive CacheLevelValue = "aggressive"
const CacheLevelValueCacheEverything CacheLevelValue = "cache_everything"
type PageRuleActionsCacheOnCookie struct{…}
ID PageRuleActionsCacheOnCookieIDoptional

Apply the Cache Everything option (Cache Level setting) based on a regular expression match against a cookie name.

Value stringoptional

The regular expression to use for matching cookie names in the request.

maxLength150
minLength1
type PageRuleActionsCacheTTLByStatus struct{…}
ID PageRuleActionsCacheTTLByStatusIDoptional

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]optional

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).
One of the following:
type PageRuleActionsCacheTTLByStatusValueString string

no-store (equivalent to -1), no-cache (equivalent to 0)

One of the following:
const PageRuleActionsCacheTTLByStatusValueStringNoCache PageRuleActionsCacheTTLByStatusValueString = "no-cache"
const PageRuleActionsCacheTTLByStatusValueStringNoStore PageRuleActionsCacheTTLByStatusValueString = "no-store"
UnionInt
type PageRuleActionsDisableApps struct{…}
ID PageRuleActionsDisableAppsIDoptional

Turn off all active Cloudflare Apps (deprecated).

type PageRuleActionsDisablePerformance struct{…}
ID PageRuleActionsDisablePerformanceIDoptional

Turn off Rocket Loader, and Polish.

type PageRuleActionsDisableSecurity struct{…}
type PageRuleActionsDisableZaraz struct{…}
ID PageRuleActionsDisableZarazIDoptional

Turn off Zaraz.

type PageRuleActionsEdgeCacheTTL struct{…}
ID PageRuleActionsEdgeCacheTTLIDoptional

Specify how long to cache a resource in the Cloudflare global network. Edge Cache TTL is not visible in response headers.

Value int64optional
maximum31536000
minimum1
type EmailObfuscation struct{…}
ID EmailObfuscationIDoptional

Turn on or off Email Obfuscation.

Value EmailObfuscationValueoptional

The status of Email Obfuscation.

One of the following:
const EmailObfuscationValueOn EmailObfuscationValue = "on"
const EmailObfuscationValueOff EmailObfuscationValue = "off"
type PageRuleActionsExplicitCacheControl struct{…}
ID PageRuleActionsExplicitCacheControlIDoptional

Origin Cache Control is enabled by default for Free, Pro, and Business domains and disabled by default for Enterprise domains.

Value PageRuleActionsExplicitCacheControlValueoptional

The status of Origin Cache Control.

One of the following:
const PageRuleActionsExplicitCacheControlValueOn PageRuleActionsExplicitCacheControlValue = "on"
const PageRuleActionsExplicitCacheControlValueOff PageRuleActionsExplicitCacheControlValue = "off"
type PageRuleActionsForwardingURL struct{…}
ID PageRuleActionsForwardingURLIDoptional

Redirects one URL to another using an HTTP 301/302 redirect. Refer to Wildcard matching and referencing.

Value PageRuleActionsForwardingURLValueoptional
StatusCode PageRuleActionsForwardingURLValueStatusCodeoptional

The status code to use for the URL redirect. 301 is a permanent redirect. 302 is a temporary redirect.

One of the following:
const PageRuleActionsForwardingURLValueStatusCode301 PageRuleActionsForwardingURLValueStatusCode = 301
const PageRuleActionsForwardingURLValueStatusCode302 PageRuleActionsForwardingURLValueStatusCode = 302
URL stringoptional

The URL to redirect the request to. Notes: ${num} refers to the position of '*' in the constraint value.

maxLength1500
type PageRuleActionsHostHeaderOverride struct{…}
ID PageRuleActionsHostHeaderOverrideIDoptional

Apply a specific host header.

Value stringoptional

The hostname to use in the Host header

minLength1
type IPGeolocation struct{…}
ID IPGeolocationIDoptional

Cloudflare adds a CF-IPCountry HTTP header containing the country code that corresponds to the visitor.

Value IPGeolocationValueoptional

The status of adding the IP Geolocation Header.

One of the following:
const IPGeolocationValueOn IPGeolocationValue = "on"
const IPGeolocationValueOff IPGeolocationValue = "off"
type Mirage struct{…}
ID MirageIDoptional

Cloudflare Mirage reduces bandwidth used by images in mobile browsers. It can accelerate loading of image-heavy websites on very slow mobile connections and HTTP/1.

Value MirageValueoptional

The status of Mirage.

One of the following:
const MirageValueOn MirageValue = "on"
const MirageValueOff MirageValue = "off"
type OpportunisticEncryption struct{…}
ID OpportunisticEncryptionIDoptional

Opportunistic Encryption allows browsers to access HTTP URIs over an encrypted TLS channel. It's not a substitute for HTTPS, but provides additional security for otherwise vulnerable requests.

Value OpportunisticEncryptionValueoptional

The status of Opportunistic Encryption.

One of the following:
const OpportunisticEncryptionValueOn OpportunisticEncryptionValue = "on"
const OpportunisticEncryptionValueOff OpportunisticEncryptionValue = "off"
type OriginErrorPagePassThru struct{…}
ID OriginErrorPagePassThruIDoptional

Turn on or off Cloudflare error pages generated from issues sent from the origin server. If enabled, this setting triggers error pages issued by the origin.

Value OriginErrorPagePassThruValueoptional

The status of Origin Error Page Passthru.

One of the following:
const OriginErrorPagePassThruValueOn OriginErrorPagePassThruValue = "on"
const OriginErrorPagePassThruValueOff OriginErrorPagePassThruValue = "off"
type Polish struct{…}
ID PolishIDoptional

Apply options from the Polish feature of the Cloudflare Speed app.

Value PolishValueoptional

The level of Polish you want applied to your origin.

One of the following:
const PolishValueOff PolishValue = "off"
const PolishValueLossless PolishValue = "lossless"
const PolishValueLossy PolishValue = "lossy"
type PageRuleActionsResolveOverride struct{…}
ID PageRuleActionsResolveOverrideIDoptional

Change the origin address to the value specified in this setting.

Value stringoptional

The origin address you want to override with.

type PageRuleActionsRespectStrongEtag struct{…}
ID PageRuleActionsRespectStrongEtagIDoptional

Turn on or off byte-for-byte equivalency checks between the Cloudflare cache and the origin server.

Value PageRuleActionsRespectStrongEtagValueoptional

The status of Respect Strong ETags

One of the following:
const PageRuleActionsRespectStrongEtagValueOn PageRuleActionsRespectStrongEtagValue = "on"
const PageRuleActionsRespectStrongEtagValueOff PageRuleActionsRespectStrongEtagValue = "off"
type ResponseBuffering struct{…}
ID ResponseBufferingIDoptional

Turn on or off whether Cloudflare should wait for an entire file from the origin server before forwarding it to the site visitor. By default, Cloudflare sends packets to the client as they arrive from the origin server.

Value ResponseBufferingValueoptional

The status of Response Buffering

One of the following:
const ResponseBufferingValueOn ResponseBufferingValue = "on"
const ResponseBufferingValueOff ResponseBufferingValue = "off"
type RocketLoader struct{…}
ID RocketLoaderIDoptional

Turn on or off Rocket Loader in the Cloudflare Speed app.

Value RocketLoaderValueoptional

The status of Rocket Loader

One of the following:
const RocketLoaderValueOn RocketLoaderValue = "on"
const RocketLoaderValueOff RocketLoaderValue = "off"
type SecurityLevel struct{…}
ID SecurityLevelIDoptional

Control options for the Security Level feature from the Security app.

Value SecurityLevelValueoptional
One of the following:
const SecurityLevelValueOff SecurityLevelValue = "off"
const SecurityLevelValueEssentiallyOff SecurityLevelValue = "essentially_off"
const SecurityLevelValueLow SecurityLevelValue = "low"
const SecurityLevelValueMedium SecurityLevelValue = "medium"
const SecurityLevelValueHigh SecurityLevelValue = "high"
const SecurityLevelValueUnderAttack SecurityLevelValue = "under_attack"
type SortQueryStringForCache struct{…}
ID SortQueryStringForCacheIDoptional

Turn on or off the reordering of query strings. When query strings have the same structure, caching improves.

Value SortQueryStringForCacheValueoptional

The status of Query String Sort

One of the following:
const SortQueryStringForCacheValueOn SortQueryStringForCacheValue = "on"
const SortQueryStringForCacheValueOff SortQueryStringForCacheValue = "off"
type SSL struct{…}
ID SSLIDoptional

Control options for the SSL feature of the Edge Certificates tab in the Cloudflare SSL/TLS app.

Value SSLValueoptional

The encryption mode that Cloudflare uses to connect to your origin server.

One of the following:
const SSLValueOff SSLValue = "off"
const SSLValueFlexible SSLValue = "flexible"
const SSLValueFull SSLValue = "full"
const SSLValueStrict SSLValue = "strict"
const SSLValueOriginPull SSLValue = "origin_pull"
type TrueClientIPHeader struct{…}
ID TrueClientIPHeaderIDoptional

Turn on or off the True-Client-IP Header feature of the Cloudflare Network app.

Value TrueClientIPHeaderValueoptional

The status of True Client IP Header.

One of the following:
const TrueClientIPHeaderValueOn TrueClientIPHeaderValue = "on"
const TrueClientIPHeaderValueOff TrueClientIPHeaderValue = "off"
type WAF struct{…}
ID WAFIDoptional

Turn on or off WAF managed rules (previous version, deprecated). You cannot enable or disable individual WAF managed rules via Page Rules.

Value WAFValueoptional

The status of WAF managed rules (previous version).

One of the following:
const WAFValueOn WAFValue = "on"
const WAFValueOff WAFValue = "off"
CreatedOn Time

The timestamp of when the Page Rule was created.

formatdate-time
ModifiedOn Time

The timestamp of when the Page Rule was last modified.

formatdate-time
Priority int64

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.

Status PageRuleStatus

The status of the Page Rule.

One of the following:
const PageRuleStatusActive PageRuleStatus = "active"
const PageRuleStatusDisabled PageRuleStatus = "disabled"
Targets []Target

The rule targets to evaluate on each request.

Constraint TargetConstraintoptional

String constraint.

Operator TargetConstraintOperator

The matches operator can use asterisks and pipes as wildcard and 'or' operators.

One of the following:
const TargetConstraintOperatorMatches TargetConstraintOperator = "matches"
const TargetConstraintOperatorContains TargetConstraintOperator = "contains"
const TargetConstraintOperatorEquals TargetConstraintOperator = "equals"
const TargetConstraintOperatorNotEqual TargetConstraintOperator = "not_equal"
const TargetConstraintOperatorNotContain TargetConstraintOperator = "not_contain"
Value string

The URL pattern to match against the current request. The pattern may contain up to four asterisks ('*') as placeholders.

Target TargetTargetoptional

A target based on the URL of the 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"
        }
      ]
    }
  ]
}