Create a Page Rule
Creates a new 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 WriteBody ParametersJSONExpand Collapse
actions: array of AlwaysUseHTTPS { id } or AutomaticHTTPSRewrites { id, value } or BrowserCacheTTL { id, value } or 31 moreThe 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.
BypassCacheOnCookie = object { id, value }
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.
CacheDeceptionArmor = object { id, value }
CacheKeyFields = object { id, value }
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 object { cookie, header, host, 2 more }
header: optional object { check_presence, exclude, include } 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.
query_string: optional object { exclude, include } 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.
CacheLevel = object { id, value }
value: optional "bypass" or "basic" or "simplified" or 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.
CacheTTLByStatus = object { id, value }
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 map["no-cache" or "no-store" or number]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).
DisableApps = object { id }
Turn off all active Cloudflare Apps (deprecated).
DisablePerformance = object { id }
Turn off Rocket Loader, and Polish.
DisableZaraz = object { id }
Turn off Zaraz.
ForwardingURL = object { id, value }
Redirects one URL to another using an HTTP 301/302 redirect. Refer
to Wildcard matching and referencing.
OpportunisticEncryption = object { id, value }
OriginErrorPagePassThru = object { id, value }
ResponseBuffering = object { id, value }
SSL = object { id, value }
WAF = object { id, value }
Turn on or off WAF managed rules (previous version, deprecated). You cannot enable or disable individual WAF managed rules via Page Rules.
The rule targets to evaluate on each request.
The rule targets to evaluate on each request.
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
actions: array of AlwaysUseHTTPS { id } or AutomaticHTTPSRewrites { id, value } or BrowserCacheTTL { id, value } or 31 moreThe 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.
BypassCacheOnCookie = object { id, value }
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.
CacheDeceptionArmor = object { id, value }
CacheKeyFields = object { id, value }
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 object { cookie, header, host, 2 more }
header: optional object { check_presence, exclude, include } 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.
query_string: optional object { exclude, include } 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.
CacheLevel = object { id, value }
value: optional "bypass" or "basic" or "simplified" or 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.
CacheTTLByStatus = object { id, value }
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 map["no-cache" or "no-store" or number]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).
DisableApps = object { id }
Turn off all active Cloudflare Apps (deprecated).
DisablePerformance = object { id }
Turn off Rocket Loader, and Polish.
DisableZaraz = object { id }
Turn off Zaraz.
ForwardingURL = object { id, value }
Redirects one URL to another using an HTTP 301/302 redirect. Refer
to Wildcard matching and referencing.
OpportunisticEncryption = object { id, value }
OriginErrorPagePassThru = object { id, value }
ResponseBuffering = object { id, value }
SSL = object { id, value }
WAF = object { id, value }
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.
Create a Page Rule
curl https://api.cloudflare.com/client/v4/zones/$ZONE_ID/pagerules \
-H 'Content-Type: application/json' \
-H "Authorization: Bearer $CLOUDFLARE_API_TOKEN" \
-d '{
"actions": [
{
"id": "browser_check",
"value": "on"
}
],
"targets": [
{
"constraint": {
"operator": "matches",
"value": "*example.com/images/*"
},
"target": "url"
}
],
"status": "active"
}'{
"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"
}
]
}
}