Transform Rules: change addresses and headers without writing a Worker
Transform Rules (URL Rewrite Rules, request and response header rules, and Managed Transforms)
What it is
Transform Rules let Cloudflare quietly adjust a request or a response as it passes through its network, using point-and-click rules in the dashboard instead of code. They live in each zone under Rules, and there are three main kinds.
URL Rewrite Rules change the path or query string that your site receives, while the visitor's address bar stays the same. This differs from a Redirect Rule (lesson 22), which tells the browser to go to a new address. Request Header Transform Rules add, change, or remove headers on the way in to your site or Worker. Response Header Transform Rules do the same on the way back out to the visitor's browser.
Each rule has two parts: a filter (for example, hostname equals one subdomain) and an action (for example, set a response header to a value). Managed Transforms are ready-made switches in the same area, such as one that adds a set of common security headers or one that removes the X-Powered-By header. Transform Rules are included on the Free plan, with a limited number of rules of each kind per zone.
Why it matters
Headers are small labels that travel with every page. Security headers tell browsers to be stricter, for example not to let another site load your page inside a frame. You can add them to every app subdomain from one place, without editing or redeploying each Worker.
It also keeps fixes in the right layer. If an old link format needs to keep working, a URL rewrite can map it to the new path behind the scenes, so the visitor never sees a redirect and the Worker code stays simple.
Rules run before your Worker sees the request and after it answers, so they apply to Workers, Pages, and a VPS behind a proxied record (lesson 1) alike. Keep each rule narrow, matching one hostname, so a change never spills onto a site you did not mean to touch.
On your account
From your own setup: this tutor runs at cloudflare.kosan.xyz on your kosan.xyz zone. A Response Header Transform Rule with the filter Hostname equals cloudflare.kosan.xyz and the action Set static, header name X-Lesson-Desk, value transform-rules, would add that label to every page here and nowhere else on kosan.xyz.
You can see headers from a terminal with curl -sI https://cloudflare.kosan.xyz/, which prints only the response headers. Once the rule is on, a line reading x-lesson-desk: transform-rules appears. Deleting the rule makes it disappear again, so the exercise is fully reversible.
Nothing was run for this lesson. This desk only redeployed its own Worker, cloudflare-tutor, and did not create any rule, change DNS, or touch the AI News root redirect rule, ainews, aiweekly, or any other Worker.
Do this yourself
These stay in the dashboard, on your side. This site does not change DNS, routes, or other Workers.
- On the kosan.xyz zone, create a Response Header Transform Rule that matches only Hostname equals cloudflare.kosan.xyz and sets the static header X-Lesson-Desk to transform-rules, run curl -sI https://cloudflare.kosan.xyz/ to see the new header, then delete or disable the rule.