The scheme and port segments are optional. If omitted, scheme matches both http:// and https:// protocols. If no port is specified, the rule will match all ports.
Finally, you can disable a page rule at any time. While a rule is disabled, actions won’t trigger, but the rule still appears in the Rules app in the Page Rules tab, is editable, and counts against the number of rules allowed for your domain. The Save as Draft option creates a page rule that is disabled by default.
Next, under Then the settings are: click + Add a Setting and select the desired setting from the dropdown. You can include more than one setting per rule. Learn more about settings in the summary below.
In the Order dropdown, specify the desired order: First, Last or Custom.
To save, click one of the following options:
Save as Draft to save the rule and leave it disabled.
Save and Deploy to save the rule and enable it immediately.
In a Forwarding URL rule, you can reference a matched wildcard in the destination URL field by using the $X syntax. X indicates the index of a glob pattern. As such, $1 represents the first wildcard match, $2 the second wildcard match, and so on.
You could forward:
This rule would match:
which ends up being forwarded to:
To use a literal $ character in the forwarding URL, escape it by adding a backslash (\) in front: \$.
Settings control the action Cloudflare takes once a request matches the URL pattern defined in a page rule. You can use settings to enable and disable multiple Cloudflare features across several of the dashboard apps. Note that:
Some settings require a Pro, Business or Enterprise domain plan.
You can specify more than one setting to apply when the rule triggers.
Below is the full list of settings available, presented in the order that they appear in the Cloudflare Page Rules UI.
Inspect the visitor’s browser for headers commonly associated with spammers and certain bots.
Bypass Cache on Cookie
Bypass Cache and fetch resources from the origin server if a regular expression matches against a cookie name present in the request. If you add both this setting and the Cache On Cookie setting to the same page rule, Cache On Cookie takes precedence over Bypass Cache on Cookie.
Also referred to as Custom Cache Key. 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.
Apply custom caching based on the option selected:
Bypass - Cloudflare does not cache. No Query String - Delivers resources from cache when there is no query string. Ignore Query String - Delivers the same resource to everyone independent of the query string. Standard - 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. Respects cache headers from the origin web server unless Edge Cache TTL is also set in the Page Rule. When combined with an Edge Cache TTL > 0, Cache Everything removes cookies from the origin web server response.
Cache on Cookie
Apply the Cache Everything option (Cache Level setting) based on a regular expression match against a cookie name. If you add both this setting and Bypass Cache on Cookie to the same page rule, Cache On Cookie takes precedence over Bypass Cache on Cookie.
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.
Turn off all active Cloudflare Apps. Note: This setting will not disable Apps with WorkersOpen external link. These apps request permission to add a Worker when you are installing them.
Turn on or off byte-for-byte equivalency checks between the Cloudflare cache and the origin server.
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.
Page Rule configuration issue leading to “Error 500 (Internal server error)”
Root cause: This may be due to a configuration issue on a Page Rule. When creating a Page Rule that uses two wildcards, like a Forwarding URL rule, it is possible to create a rule that mentions the second wildcard with the $2 placeholder. Refer to the example below:
When updating the same rule, you can remove one of the wildcard in the If the URL matches field and save it. Refer to the example below:
If you do so, the $2 placeholder reference a wildcard that does not exist anymore, and as such, an “Error 500 (Internal server error)” is thrown when a URL triggers the page rule.
Resolution: Update the Page Rule and remove the reference $2 to the second wildcard. If there is only one wildcard, then only $1 can be used.
This setting is available to business and enterprise customers.
The Bypass Cache on Cookie setting supports basic regular expressions (regex) as follows:
A pipe operator (represented by |) to match multiple cookies using OR boolean logic. For example, bypass=.*|PHPSESSID=.* would bypass the cache if either a cookie called bypass or PHPSESSID were set, regardless of the cookie’s value.
The wildcard operator (represented by .*), such that a rule value of t.*st= would match both a cookie called test and one called teeest.
150 chars per cookie regex
12 wildcards per cookie regex
1 wildcard in between each | in the cookie regex
To learn how to configure Bypass Cache on Cookie with a variety of platforms, review these articles:
When saving a Page Rule, Cloudflare will ensure that there is a slash after each occurrence of the current zone name in the If the URL matches field. For example, if the current zone name is example.com, then:
example.com will be saved as example.com/
example.com/path/example.com will be saved as example.com/path/example.com/
Note that example.com/some-path/cloudflare.com will be saved without a final slash, since the zone name is not cloudflare.com.
If the URL of the current request matches both a Page Rule and a Workers custom route, some Pages Rules settings will not be applied. For details on using Page Rules with Workers, refer to Workers: Page Rules in the developers documentation.