Page Rules give you the ability to take various actions based on the page's URL, such as creating redirects, fine tuning caching behavior, or enabling and disabling our various services.

A Page Rule will take effect on a given URL pattern, matching the following format:

<scheme>://<hostname><:port>/<path>

An example using each component would be:

https://www.example.com:80/image.png

The scheme and port components are optional. If the scheme is omitted, it will cover both http:// and https:// protocols. If the port is not specified, then the rule will match all ports. You can perform basic wildcard matches by using an asterisk (*) in your rule pattern, allowing it to match a series of similar patterns rather than just one.

There are two important things to note with Page Rules:

Only one Page Rule takes effect on any given request.

Page Rules are given priority in an order from top to bottom.

Once a URL matches a rule, only that rule only will be applied; for example, if a Page Rule has already triggered on a request, any subsequent rules that also match the URL pattern will not take effect. As a general rule, we recommend ordering your rules from most specific to least specific.

Page rules can be paused, in which case no action triggers but the rule still appears in the list and can be edited. The Save as Draft option creates a page rule that is paused by default.

The specific actions a Page Rule can take are described below:

Forwarding:

Redirects one URL to another using an HTTP 301/302 redirect. The contents of any URL segment matching a wildcard can be referenced later using the $X syntax. X indicates the index of a glob in the pattern: $1 will be replaced with the first wildcard match, $2 with the second wildcard match, and so on.

Only wildcards can be leveraged in page rules. Full regex support is not currently available.

For example, suppose you set the following rule:

Here, a request to "www.example.com/stuff/things" will be redirected to "http://example.com/stuff/things".

***NOTE***

Be careful not to create a redirect where the domain points to itself as a destination. This can cause an infinite redirect error and the affected URLs will not be resolved.

**********

If you want to use a $ in the forwarding URL not as a variable, you will need to escape it, by adding a backslash (\) before the $.

Custom Caching:

Sets caching behavior for any URL matching the page rule pattern, using any of our standardcache levels. The Cache everything setting will cache any content, even if it is not one of ournormal static file types. The Bypass setting will prevent caching on that URL.

Ports 80, 443, and 8080 are the only ports where Cloudflare Caching is available.

When specifying cache level via page rules, you can optionally set an edge cache TTL, which controls how long we will retain files in our cache. By default, this setting is to respect all existing headers, which usesstandard HTTP caching headers to control cache age. You may set other cache lifetimes directly, depending on your plan.

Browser Cache TTL controls how long resources cached by client browsers remain valid. If a browser requests a resource again and the TTL has not expired, it will receive an HTTP 304 (Not Modified) response. If you send a max-age header that is longer than this TTL, that value will take precedence. Free, Pro, and Business customers can set TTLs ranging from 30 minutes to 1 year; Enterprise customers have additional options down to 30 seconds, and can choose to respect the existing max-age header.

The Following example will set a rule to cache everything found in the "/images" folder. Cached resources will expire in 5 minutes in the user's browser, and will expire after one day in Cloudflare's data centers:

Edge Cache TTL will tell our edge how long to keep an object in our edge cache, specifically. While Browser Cache TTL will dictate how long the client will keep the object in its local cache.

The following options are available to all plan levels:

Always Online:

Controls whether we will attempt to serve content from ourAlways Online cache. You may wish to disable this for sections of your site that should never return cached data, such as APIs or payment/cart pages.

Apps:

Will toggle all Cloudflare Apps on or off.

Mirage:

Rocket Loader:

SSL:

Security Level:

Controls how high a client threat score must be for a client to see a challenge page, and can be used to set part of your site to always present visitors with theUnder Attack mode challenge before they can visit your site.

WAF:

Browser Integrity Check:

Always Use HTTPS:

Convert any http:// URL to an https:// URL by creating a 301 redirect. This is commonly used if you want to force some sections of your site to HTTPS, which uses certificates to secure the connection between a client and our edge.

IP Geolocation Header:

Includes the country code of the visitor location with all requests to your website. The information will be found in the CF-IPCountry HTTP header.

Resolve Override (Enterprise Only):

Custom Cache Key (Enterprise Only):

Control specifically what variables are included when deciding what resources to cache; that is, it allows the user to determine what to cache based on something other than just the URL. Note that the user will not be able to control this directly. Custom cache keys will need to be requested from Cloudflare Support.

Query String Sort (Enterprise Only):

Origin Error Page Pass Through (Enterprise Only):

Disables Cloudflare error pages that would trigger for issues sent from the origin server, and instead shows the error pages set at the origin.

True Client IP Header (Enterprise Only):

By default, Cloudflare sends back packets with a Cloudflare IP address. If True-Client-IP is enabled, Cloudflare adds a True-Client-IP header in the request sent to the origin with the IP address of the end user.

Max Upload Size (Enterprise Only):

Cloudflare limits the maximum amount of data a visitor can upload per request. The limit is determined by the plan level:

Free: 100MB

Pro: 100MB

Business: 200MB

Enterprise: 500MB (default)

Response Buffering (Enterprise Only):

Cloudflare waits until it has the entire file before forwarding it to the end user. By default, Cloudflare sends packets to the client as we receive them.