Edit a Page Rule
Updates one or more fields of an existing Page Rule.
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 WritePage Rules WriteParametersExpand Collapse
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.
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.
class ActionBypassCacheOnCookie: …
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.
class ActionCacheDeceptionArmor: …
class ActionCacheKeyFields: …
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: Optional[ActionCacheKeyFieldsValue]
header: Optional[ActionCacheKeyFieldsValueHeader]Controls 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: Optional[ActionCacheKeyFieldsValueHost]Determines which host header to include in the Cache Key.
Determines which host header to include in the Cache Key.
query_string: Optional[ActionCacheKeyFieldsValueQueryString]Controls 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.
class CacheLevel: …
value: Optional[Literal["bypass", "basic", "simplified", 2 more]]
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.
class ActionCacheTTLByStatus: …
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: Optional[Dict[str, Union[Literal["no-cache", "no-store"], int]]]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).
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).
class ActionDisableApps: …
Turn off all active Cloudflare Apps (deprecated).
class ActionDisablePerformance: …
Turn off Rocket Loader, and Polish.
class ActionDisableZaraz: …
Turn off Zaraz.
class ActionForwardingURL: …
Redirects one URL to another using an HTTP 301/302 redirect. Refer
to Wildcard matching and referencing.
class OpportunisticEncryption: …
class OriginErrorPagePassThru: …
class ResponseBuffering: …
class SSL: …
class WAF: …
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.
ReturnsExpand Collapse
class PageRule: …
actions: List[Action]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.
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.
class ActionBypassCacheOnCookie: …
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.
class ActionCacheDeceptionArmor: …
class ActionCacheKeyFields: …
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: Optional[ActionCacheKeyFieldsValue]
header: Optional[ActionCacheKeyFieldsValueHeader]Controls 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: Optional[ActionCacheKeyFieldsValueHost]Determines which host header to include in the Cache Key.
Determines which host header to include in the Cache Key.
query_string: Optional[ActionCacheKeyFieldsValueQueryString]Controls 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.
class CacheLevel: …
value: Optional[Literal["bypass", "basic", "simplified", 2 more]]
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.
class ActionCacheTTLByStatus: …
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: Optional[Dict[str, Union[Literal["no-cache", "no-store"], int]]]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).
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).
class ActionDisableApps: …
Turn off all active Cloudflare Apps (deprecated).
class ActionDisablePerformance: …
Turn off Rocket Loader, and Polish.
class ActionDisableZaraz: …
Turn off Zaraz.
class ActionForwardingURL: …
Redirects one URL to another using an HTTP 301/302 redirect. Refer
to Wildcard matching and referencing.
class OpportunisticEncryption: …
class OriginErrorPagePassThru: …
class ResponseBuffering: …
class SSL: …
class WAF: …
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.
Edit a Page Rule
import os
from cloudflare import Cloudflare
client = Cloudflare(
api_token=os.environ.get("CLOUDFLARE_API_TOKEN"), # This is the default and can be omitted
)
page_rule = client.page_rules.edit(
pagerule_id="023e105f4ecef8ad9ca31a8372d0c353",
zone_id="023e105f4ecef8ad9ca31a8372d0c353",
)
print(page_rule.id){
"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"
}
]
}
}