Skip to content
Rules
Visit Rules on GitHub
Set theme to dark (⇧+D)

About Transform Rules

Transform Rules allow you to make adjustments to incoming requests at the edge before they go through any other Cloudflare products.

There are two types of Transform Rules:

  • URL Rewrite Rules:
    • Rewrite the path of the URL of an HTTP request
    • Rewrite the query string of the URL of an HTTP request
  • HTTP Request Header Modification Rules:
    • Set the value of an HTTP request header
    • Remove an HTTP request header

To configure Transform Rules in the dashboard, use the Transform Rules tab in Rules.

Create a URL Rewrite RuleCreate a Header Modification RuleExamples


URL Rewrite Rules

A URL Rewrite Rule can perform a static rewrite or a dynamic rewrite. Static rewrites replace a given part of a request URL (path or query string) with a static string. Dynamic rewrites support more advanced scenarios where you use an expression to define the resulting path or query string.

To create a URL Rewrite Rule in the dashboard, see Create a URL Rewrite Rule in the dashboard.

To create a URL Rewrite Rule via API, see Create a URL Rewrite Rule via API.

Rewrites and redirects

You can manipulate the URL of a request through different operations, namely through rewrites and redirects.

A rewrite is a server-side operation that occurs before a web server has fully processed a request. A rewrite is not visible to website visitors, since the URL displayed in the browser does not change.

A redirect is a client-side operation that occurs after the web server has loaded the initial URL. In this case, a website visitor can see the URL changing when the redirect occurs.

You can configure URL Rewrite Rules in the dashboard to perform rewrites at the edge without reaching your web server. URL Rewrite Rules run in the http_request_transform Phase of Cloudflare's request handling workflow. For more information on Phases, check the Ruleset Engine documentation.

Check Configuring URL forwarding or redirects with Cloudflare Page Rules in the Support KB to learn more about configuring redirects.


HTTP Request Header Modification Rules

You can manipulate the headers of incoming HTTP requests through HTTP Request Header Modification Rules. Through these rules you can:

  • Set the value of an HTTP request header to a literal string value, overwriting its previous value or adding a new header to the request.
  • Set the value of an HTTP request header according to an expression, overwriting its previous value or adding a new header to the request.
  • Remove an HTTP request header from the request (remove all headers with the provided name).

HTTP Request Header Modification Rules run in the http_request_late_transform Phase of Cloudflare's request handling workflow. For more information on Phases, see Phases in the Ruleset Engine documentation.

To create an HTTP Request Header Modification Rule in the dashboard, see Create an HTTP Request Header Modification Rule in the dashboard.

To create an HTTP Request Header Modification Rule via API, see Create an HTTP Request Header Modification Rule via API.


Availability

Cloudflare Transform Rules are available to all customers. Keep in mind that support for regular expressions is based on your plan type.

This table outlines the Transform Rules features available with each customer plan:

FeatureFreeProBusinessEnterprise
Active URL Rewrite Rules251020
Active HTTP Request Header Modification Rules251020
Regular expression supportNoNoYesYes

Get started

To get started building your own Transform Rules, see:

You can also create Transform Rules via API.

For common Transform Rule scenarios, see Common use cases.

Check Firewall Rules language for more information on building expressions for Transform Rules, since the language is the same as the Firewall Rules language.