Reference guide · cloudflare · Published 2026-08-16 · 4 min read

Cloudflare Transform Rules for headers

Use Cloudflare Transform Rules to set, add, or remove request and response headers at the edge without code. Free plan quota and Worker comparison included.

Flat editorial illustration showing a planetary shield with concentric orbit rings, one radial segment glowing as a small request dot climbs.
Illustration: this article at a glance.

What a Transform Rule does

Transform Rules edit the HTTP request or response while traffic crosses the Cloudflare edge, with no code on your origin or in a Worker. There are three families:

Editorial close-up illustration showing a planetary shield with concentric orbit rings, one radial segment glowing as a small request dot settles.
Illustration: a closer look at the technique described above.
FamilyWhat it changesRuns on
Request header modificationSet, add, or remove request headers sent to the originThe outbound leg to your server
Response header modificationSet, add, or remove response headers sent to visitorsThe inbound leg back to the browser
URL rewriteRewrite the path and query string before the origin sees itThe request path

Each matching request or response runs against the rule set. The header operations are declarative: set overwrites, add keeps existing values, and remove deletes the header. Dynamic values can be pulled from request fields (for example the visitor country or cf-connecting-ip), so a rule can stamp X-Visitor-Country for every request without the origin doing any work.

Free plan limits (the ones that usually bite)

LimitFreeProBusinessEnterprise
Active Transform Rules102550300
Regular expressions in rulesNoNoYesYes

When a job fits inside one or two rules, Transform Rules beat a Worker: no worker to deploy, no bundle to patch, no CPU budget to watch. The dashboard route also means someone who only has firewall/administrator access can add the rule without code review.

Header examples

Request header (set a forwarding header on the way to the origin):

if: http.host equals "www.example.com"
action: set  X-Forwarded-Prefix  /support

Response header (stamp a Content-Security-Policy for every page):

if: true
  action: set  Content-Security-Policy  "default-src 'self'"

Response header, dynamic (add the visitor country):

if: true
  action: add  X-Visitor-Country  {http.request.geo.country}

Header transforms are set at the zone level and cannot be scoped per environment until you add a matching hostname rule. If you need device-type caching, the same device-type header used for the cache key can be injected here rather than re-writing it in the app.

When not to use a Transform Rule

The comparison table

NeedTransform RuleWorker
Set/remove a few headers on matched trafficYes, smallest optionOverkill
Change the URL path or queryYes (URL Rewrite family)Yes
Inspect or alter the response bodyNoYes
Regex matchingBusiness and upAlways
Adds a request per matchNo extra requestRuns per request

The rule that decides which route to take is scope: headers on defined traffic, Transform Rules; anything that computes from the body, needs to be conditional in a way your plan can't express, or runs beyond the header layer, a Worker. The Workers basics guide shows the trade-off from the other side.

Need a website built, fixed, optimised, migrated or replaced?

This technical resource is written by CSMBAC, a small design and development studio. If you would rather hand the problem to a professional, the website service page explains how we build enquiry-ready websites.

Explore website services