---
title: Rules examples
description: Example configurations for Transform Rules, redirects, origin rules, and more.
image: https://developers.cloudflare.com/core-services-preview.png
---

> Documentation Index  
> Fetch the complete documentation index at: https://developers.cloudflare.com/rules/llms.txt  
> Use this file to discover all available pages before exploring further.

[Skip to content](#%5Ftop) 

# Rules examples

Explore the following examples for Rules.

Note

We have a separate listing for [Cache rules examples](https://developers.cloudflare.com/cache/how-to/cache-rules/examples/).

Filter resources...

[Route /images to an S3 Bucket using TerraformRoute requests with a URI path starting with /images to a specific AWS S3 bucket with Cloud Connector using Terraform.](https://developers.cloudflare.com/rules/cloud-connector/examples/route-images-to-aws-s3-using-terraform/)[Route /images to an S3 BucketRoute requests with a URI path starting with /images to a specific AWS S3 bucket using Cloud Connector.](https://developers.cloudflare.com/rules/cloud-connector/examples/route-images-to-s3/)[Send EU visitors to a Google Cloud Storage bucketRoute all traffic from EU visitors to a Google Cloud Storage bucket using Cloud Connector.](https://developers.cloudflare.com/rules/cloud-connector/examples/send-eu-visitors-to-gcs/)[Serve /static-assets from Azure Blob StorageRoute requests with a URI path starting with /static-assets to an Azure Blob Storage container using Cloud Connector.](https://developers.cloudflare.com/rules/cloud-connector/examples/serve-static-assets-from-azure/)[Disable Brotli compressionCreate a compression rule to turn off Brotli compression for all incoming requests of a given zone.](https://developers.cloudflare.com/rules/compression-rules/examples/disable-all-brotli/)[Disable compression for AVIF imagesCreate a compression rule to turn off compression for AVIF images, based on either the content type or the file extension specified in the request.](https://developers.cloudflare.com/rules/compression-rules/examples/disable-compression-avif/)[Enable Zstandard compression for default content typesCreate a compression rule to turn on Zstandard compression for response content types where Cloudflare applies compression by default.](https://developers.cloudflare.com/rules/compression-rules/examples/enable-zstandard/)[Use Gzip compression for CSV filesCreate a compression rule to set Gzip compression as the preferred compression method for CSV files.](https://developers.cloudflare.com/rules/compression-rules/examples/gzip-for-csv/)[Use only Brotli compression for a specific pathCreate a compression rule to set Brotli as the only supported compression algorithm for a specific URI path.](https://developers.cloudflare.com/rules/compression-rules/examples/only-brotli-url-path/)[Define a single configuration rule using TerraformCreate a configuration rule using Terraform to turn off Email Obfuscation and Browser Integrity Check for API requests in a given zone.](https://developers.cloudflare.com/rules/configuration-rules/examples/define-single-configuration-terraform/)[Change the HTTP Host header and DNS recordCreate an origin rule to change the HTTP Host header and the resolved DNS record.](https://developers.cloudflare.com/rules/origin-rules/examples/change-http-host-header/)[Change the destination portCreate an origin rule to change the destination port.](https://developers.cloudflare.com/rules/origin-rules/examples/change-port/)[Define a single origin rule using TerraformCreate an origin rule using Terraform to override the Host header, the resolved hostname, and the destination port of API requests.](https://developers.cloudflare.com/rules/origin-rules/examples/define-single-origin-terraform/)[A/B testing with same-URL direct accessSet up an A/B test by controlling what response is served based on cookies.](https://developers.cloudflare.com/rules/snippets/examples/ab-testing-same-url/)[Append dates to cookies to use with A/B testingDynamically set a cookie expiration and test group.](https://developers.cloudflare.com/rules/snippets/examples/append-dates-to-cookies/)[Auth with headersAllow or deny a request based on a known pre-shared key in a header. This is not meant to replace the WebCrypto API.](https://developers.cloudflare.com/rules/snippets/examples/auth-with-headers/)[Send Bot Management information to originSend Bots information to your origin. Refer to Bot Management variables for a full list of available fields.](https://developers.cloudflare.com/rules/snippets/examples/bot-data-to-origin/)[Send suspect bots to a honeypotUse the bot score field to send bots to a honeypot.](https://developers.cloudflare.com/rules/snippets/examples/bots-to-honeypot/)[Bulk redirect based on a map objectRedirect requests to certain URLs based on a mapped object to the request's URL.](https://developers.cloudflare.com/rules/snippets/examples/bulk-redirect-map/)[Country code redirectRedirect a response based on the country code in the header of a visitor.](https://developers.cloudflare.com/rules/snippets/examples/country-code-redirect/)[Custom cacheStore, retrieve, and remove assets from cache programmatically. Use this template to optimize performance and implement custom caching strategies.](https://developers.cloudflare.com/rules/snippets/examples/custom-cache/)[Debugging logsSend debugging information in an errored response to a logging service.](https://developers.cloudflare.com/rules/snippets/examples/debugging-logs/)[Define CORS headersAdjust Cross-Origin Resource Sharing (CORS) headers and handle preflight requests.](https://developers.cloudflare.com/rules/snippets/examples/define-cors-headers/)[Follow redirects from the originModify the fetch request to follow redirects from the origin, ensuring the client receives the final response.](https://developers.cloudflare.com/rules/snippets/examples/follow-redirects/)[Add HEX timestamp to a request headerAdd a custom header to requests sent to the origin server with the current timestamp in hexadecimal format for debugging, tracking, or custom routing purposes.](https://developers.cloudflare.com/rules/snippets/examples/hex-timestamp/)[Validate JSON web tokens (JWT)Extract a JWT from the Authorization header, verify its HMAC-SHA256 signature using the WebCrypto API, and validate its claims.](https://developers.cloudflare.com/rules/snippets/examples/jwt-validation/)[Maintenance pageServe a custom maintenance page instead of fetching content from the origin server or cache. Ideal for downtime notifications, planned maintenance, or emergency messages.](https://developers.cloudflare.com/rules/snippets/examples/maintenance/)[Override a Set-Cookie header with a certain valueGet a specific Set-Cookie header and update it with a certain value.](https://developers.cloudflare.com/rules/snippets/examples/override-set-cookies-value/)[Redirect 403 Forbidden to a different pageIf origin responded with 403 Forbidden error code, redirect to different page.](https://developers.cloudflare.com/rules/snippets/examples/redirect-forbidden-status/)[Redirect from one domain to anotherRedirect all requests from one domain to another domain.](https://developers.cloudflare.com/rules/snippets/examples/redirect-replaced-domain/)[Remove fields from API responseIf origin responds with JSON, parse the response and delete fields to return a modified response.](https://developers.cloudflare.com/rules/snippets/examples/remove-fields-api-response/)[Remove query strings before sending request to originRemove certain query strings from a request before passing to the origin.](https://developers.cloudflare.com/rules/snippets/examples/remove-query-strings/)[Remove response headersRemove from response all headers that start with a certain name.](https://developers.cloudflare.com/rules/snippets/examples/remove-response-headers/)[Return information about the incoming requestRespond with information about the incoming request provided by Cloudflare’s global network.](https://developers.cloudflare.com/rules/snippets/examples/return-incoming-request-properties/)[Rewrite links on HTML pagesDynamically rewrite links in HTML responses. This is useful for site migrations and branding updates.](https://developers.cloudflare.com/rules/snippets/examples/rewrite-site-links/)[Change origin and modify pathsRoute requests to a different origin, prepend a directory to the URL path, and remove specific segments.](https://developers.cloudflare.com/rules/snippets/examples/route-and-rewrite/)[Set security headersSet common security headers such as X-XSS-Protection, X-Frame-Options, and X-Content-Type-Options.](https://developers.cloudflare.com/rules/snippets/examples/security-headers/)[Send timestamp to origin as a custom headerConvert timestamp to hexadecimal format and send it as a custom header to the origin.](https://developers.cloudflare.com/rules/snippets/examples/send-timestamp-to-origin/)[Route to a different origin based on origin responseIf response to the original request is not 200 OK or a redirect, send to another origin.](https://developers.cloudflare.com/rules/snippets/examples/serve-different-origin/)[Sign requestsVerify a signed request using the HMAC and SHA-256 algorithms or return a 403.](https://developers.cloudflare.com/rules/snippets/examples/signing-requests/)[Slow down suspicious requestsDefine a delay to be used when incoming requests match a rule you consider suspicious based on the bot score.](https://developers.cloudflare.com/rules/snippets/examples/slow-suspicious-requests/)[Add a wildcard CORS response headerCreate a CORS response header transform rule to add an Access-Control-Allow-Origin HTTP header to the response with wildcard as static value. (cookiename=value).](https://developers.cloudflare.com/rules/transform/examples/add-cors-header/)[Add a request header with the current bot scoreCreate a request header transform rule to add a X-Bot-Score HTTP header to the request with the current bot score.](https://developers.cloudflare.com/rules/transform/examples/add-request-header-bot-score/)[Add request header with a static valueCreate a request header transform rule to add an X-Source HTTP header to the request with a static value (Cloudflare).](https://developers.cloudflare.com/rules/transform/examples/add-request-header-static-value/)[Add a request header for subrequests from other zonesCreate a request header transform rule to add an HTTP header when the Workers subrequest comes from a different zone.](https://developers.cloudflare.com/rules/transform/examples/add-request-header-subrequest-other-zone/)[Add a response header with a static valueCreate a response header transform rule to add a set-cookie HTTP header to the response with a static value (cookiename=value).](https://developers.cloudflare.com/rules/transform/examples/add-response-header-static-value/)[Normalize encoded slashes in URL pathCreate a URL rewrite rule (part of Transform Rules) to normalize encoded forward slashes (%2F) in the request path to standard slashes (/).](https://developers.cloudflare.com/rules/transform/examples/normalize-encoded-slash/)[Remove a request headerCreate a request header transform rule (part of Transform Rules) to remove the cf-connecting-ip HTTP header from the request.](https://developers.cloudflare.com/rules/transform/examples/remove-request-header/)[Remove a response headerCreate a response header transform rule (part of Transform Rules) to remove the cf-connecting-ip HTTP header from the response.](https://developers.cloudflare.com/rules/transform/examples/remove-response-header/)[Rewrite blog archive URLsCreate a transform rule to rewrite the URL format /posts/<YYYY>-<MM>-<DD>-<TITLE> to the new format /posts/<YYYY>/<MM>/<DD>/<TITLE>.](https://developers.cloudflare.com/rules/transform/examples/rewrite-archive-urls-new-format/)[Rewrite path of moved section of a websiteCreate a URL rewrite rule (part of Transform Rules) to rewrite everything under /blog/<PATH> to /marketing/<PATH>.](https://developers.cloudflare.com/rules/transform/examples/rewrite-moved-section/)[Rewrite path of archived blog postsCreate a URL rewrite rule (part of Transform Rules) to rewrite any requests for /news/2012/... URI paths to /archive/news/2012/....](https://developers.cloudflare.com/rules/transform/examples/rewrite-path-archived-posts/)[Rewrite path for object storage bucketCreate a URL rewrite rule (part of Transform Rules) to rewrite any requests for /files/... URI paths to /....](https://developers.cloudflare.com/rules/transform/examples/rewrite-path-object-storage/)[Rewrite image paths with several URL segmentsCreate a URL rewrite rule (part of Transform Rules) to rewrite any requests for /images/<FOLDER1>/<FOLDER2>/<FILENAME> to /img/<FILENAME>.](https://developers.cloudflare.com/rules/transform/examples/rewrite-several-url-different-url/)[Rewrite URL query stringCreate a transform rule to rewrite the request path from /blog to /blog?sort-by=date.](https://developers.cloudflare.com/rules/transform/examples/rewrite-url-string-visitors/)[Rewrite page path for visitors in specific countriesCreate two URL rewrite rules (part of Transform Rules) to rewrite the path of the welcome page for visitors in specific countries.](https://developers.cloudflare.com/rules/transform/examples/rewrite-welcome-for-countries/)[Set a response header with the current bot scoreCreate a response header transform rule (part of Transform Rules) to set an X-Bot-Score HTTP header in the response with the current bot score.](https://developers.cloudflare.com/rules/transform/examples/set-response-header-bot-score/)[Set response header with a static valueCreate a response header transform rule (part of Transform Rules) to set an X-Bot-Score HTTP header in the response to a static value (Cloudflare).](https://developers.cloudflare.com/rules/transform/examples/set-response-header-static-value/)[Perform mobile redirectsCreate a redirect rule to redirect visitors using mobile devices to a different hostname.](https://developers.cloudflare.com/rules/url-forwarding/examples/perform-mobile-redirects/)[Redirect admin area requests to HTTPSCreate a redirect rule to redirect requests for the administration area of store.example.com to HTTPS, keeping the original path and query string.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-admin-https/)[Redirect requests from one domain to anotherCreate a redirect rule to redirect all requests to a different domain, maintaining all functionality, except for the discontinued HTTP service (port 80).](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-all-another-domain/)[Redirect requests from one country to a domainCreate a redirect rule to redirect all website visitors from the United Kingdom to a different domain, maintaining the current functionality in the same paths.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-all-country/)[Redirect requests for a domain to a new domainCreate a redirect rule to redirect all URLs for a domain to point to the root of a new domain, including any subdomains of the old domain.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-all-different-domain-root/)[Redirect requests to a different hostnameCreate a redirect rule to redirect all requests for smallshop.example.com to a different hostname using HTTPS, keeping the original path and query string.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-all-different-hostname/)[Redirect local visitors to specific subdomainsCreate 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.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-country-subdomains/)[Redirect visitors to a new page URLCreate a redirect rule to redirect visitors from /contact-us/ to the page's new path /contacts/.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-new-url/)[Redirect from root to WWWCreate a redirect rule to forward HTTPS requests from the root (also known as the “apex” or “naked” domain) to the WWW subdomain.](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-root-to-www/)[Redirect from WWW to rootCreate a redirect rule to forward HTTPS requests from the WWW subdomain to the root (also known as the “apex” or “naked” domain).](https://developers.cloudflare.com/rules/url-forwarding/examples/redirect-www-to-root/)[Remove locale from URL pathCreate a redirect rule to redirect visitors from an old URL format with locale information to a new URL format.](https://developers.cloudflare.com/rules/url-forwarding/examples/remove-locale-url/)

```json
{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"item":{"@id":"/directory/","name":"Directory"}},{"@type":"ListItem","position":2,"item":{"@id":"/rules/","name":"Rules"}},{"@type":"ListItem","position":3,"item":{"@id":"/rules/examples/","name":"Rules examples"}}]}
```
