Skip to content

Examples

Explore the following examples for Rules.

70 examples

Add a response header with a static value

Create a response header modification rule (part of Transform Rules) to add a set-cookie HTTP header to the response with a static value (cookiename=value).

Transform Rules

Add request header with a static value

Create a request header modification rule (part of Transform Rules) to add an X-Source HTTP header to the request with a static value (Cloudflare).

Transform Rules

Change URI Path and Host Header

Learn how to adjust the URI path and Host header for incoming requests. This example demonstrates using both Transform Rules and Origin Rules to achieve simultaneous modifications.

Transform Rules, Origin Rules

Country code redirect

Redirect a response based on the country code in the header of a visitor.

Snippets

Debugging logs

Send debugging information in an errored response to a logging service.

Snippets

Disable Brotli compression

Create a compression rule to turn off Brotli compression for all incoming requests of a given zone.

Compression Rules

Disable compression for AVIF images

Create a compression rule to turn off compression for AVIF images, based on either the content type or the file extension specified in the request.

Compression Rules

Perform mobile redirects

Create a redirect rule to redirect visitors using mobile devices to a different hostname.

Redirect Rules

Redirect admin area requests to HTTPS

Create a redirect rule to redirect requests for the administration area of store.example.com to HTTPS, keeping the original path and query string.

Redirect Rules

Redirect from root to WWW

Create a redirect rule to forward HTTPS requests from the root (also known as the “apex” or “naked” domain) to the WWW subdomain.

Redirect Rules

Redirect from WWW to root

Create a redirect rule to forward HTTPS requests from the WWW subdomain to the root (also known as the “apex” or “naked” domain).

Redirect Rules

Redirect local visitors to specific subdomains

Create a redirect rule to redirect United Kingdom and France visitors from the example.com website's root path (/) to their localized subdomains https://gb.example.com and https://fr.example.com, respectively.

Redirect Rules

Redirect requests to a different hostname

Create a redirect rule to redirect all requests for smallshop.example.com to a different hostname using HTTPS, keeping the original path and query string.

Redirect Rules

Remove a request header

Create a request header modification rule (part of Transform Rules) to remove the cf-connecting-ip HTTP header from the request.

Transform Rules

Remove a response header

Create a response header modification rule (part of Transform Rules) to remove the cf-connecting-ip HTTP header from the response.

Transform Rules

Remove locale from URL path

Create a redirect rule to redirect visitors from an old URL format with locale information to a new URL format.

Redirect Rules

Rewrite blog archive URLs

Create a transform rule to rewrite the URL format /posts/<YYYY>-<MM>-<DD>-<TITLE> to the new format /posts/<YYYY>/<MM>/<DD>/<TITLE>.

Transform Rules

Rewrite path of archived blog posts

Create a rewrite URL rule (part of Transform Rules) to rewrite any requests for /news/2012/... URI paths to /archive/news/2012/....

Transform Rules

Rewrite URL query string

Create a transform rule to rewrite the request path from /blog to /blog?sort-by=date.

Transform Rules

Route /images to an S3 Bucket

Route requests with a URI path starting with /images to a specific AWS S3 bucket using Cloud Connector.

Cloud Connector

Set response header with a static value

Create a response header modification rule (part of Transform Rules) to set an X-Bot-Score HTTP header in the response to a static value (Cloudflare).

Transform Rules

Set security headers

Set common security headers such as X-XSS-Protection, X-Frame-Options, and X-Content-Type-Options.

Snippets

Sign requests

Verify a signed request using the HMAC and SHA-256 algorithms or return a 403.

Snippets