RedirectForge by ThemeMend

Cloudflare Redirect Rule builder: Page Rule or wildcard pattern to a Single Redirect

Paste the Page Rule URL and its Forwarding URL, or any old-to-new wildcard or regex pattern. You get the dashboard fields, the custom expression with wildcard_replace(), the regex form, the API JSON and a Terraform rule, with the ${N} capture numbers shifted correctly. Free, no signup. Load an example.

Output updates as you type. Nothing is stored.

The rule appears here in five shapes: dashboard fields, custom expression, regex (Business or Enterprise), API JSON and Terraform. Each has a Copy button.

How capture numbering shifts

A Page Rule counts its wildcards from the host onward. A Redirect Rule counts from the scheme, because it matches the whole URL.

Fixed scheme: numbers stay put

Page Rule www.example.com/* forwarding to https://example.com/$1 becomes request URL https://www.example.com/* and target https://example.com/${1}. One wildcard, one capture.

Both schemes: every number moves up one

To match http and https the pattern is http*://www.example.com/*. The * in http* is capture ${1}, so the path wildcard is ${2} and the target is https://example.com/${2}. With two path wildcards, $1 and $2 become ${2} and ${3}.

Cloudflare's own migration guide documents exactly this pair, and it is the mistake that produces a redirect whose target is the literal scheme name or a blank segment. The builder counts the wildcards in the source, applies the shift when the scheme is agnostic, and refuses a target that references a capture the source does not have.

Other rules the builder enforces from the Cloudflare documentation: the wildcard operator is case-insensitive and strict wildcard is case-sensitive; the whole field must match; each * is zero or more characters and crosses /; a literal asterisk is \* and a literal backslash is \\; two asterisks in a row are invalid; wildcard_replace() and regex_replace() expose captures ${1} to ${8}.

Many rules at once

One rule per line as source -> target [status]. Tab or comma separators work too. Uses the mode, status and toggles set above. Free up to 10 rules per call; Pro removes the cap.

Lines starting with # are ignored. Load an example.

curl -X POST https://redirectforge.thememend.com/api/cf-rules \
  -H "x-api-key: YOUR_KEY" -H "Content-Type: application/json" \
  -d '{"lines":"www.example.com/* -> https://example.com/$1\nexample.com/promo -> https://example.com/sale 302","mode":"pagerule"}'

The response carries a combined rules[] array you can PUT to the zone's http_request_dynamic_redirect entrypoint ruleset, plus one Terraform resource. Without a key the same call is free up to 10 rules. Single rules: POST /api/cf-rule with {"mode","source","target","status","preserveQuery","schemeAgnostic","caseSensitive"}, no key needed.

Frequently asked questions

Why does $1 from my Page Rule become ${2} in the Redirect Rule?

Redirect Rules match the full URL, scheme included. To match both http and https the request URL pattern starts with http*://, and that * is a wildcard like any other: it is capture ${1}. Every wildcard after it moves up one, so the Page Rule's $1 is ${2}, $2 is ${3} and so on. If you fix the scheme (https://www.example.com/*) there is no extra wildcard and $1 stays ${1}. The builder applies the shift for you and shows which case you are in.

Which Cloudflare plans can use the regex form?

The matches operator and the regex_replace() function need a Business or Enterprise plan. The wildcard operator and wildcard_replace() work on every plan, including Free, so the builder shows the wildcard form first and labels the regex form Business or Enterprise.

Why is ** rejected?

In a Cloudflare wildcard pattern a single * already matches zero or more characters, including slashes. Two unescaped asterisks in a row are not a valid pattern and Cloudflare will not save the rule, so the builder stops with an error instead of producing a rule that cannot be published. Write \* for a literal asterisk.

Does the generated rule handle query strings?

The wildcard form matches http.request.full_uri, which includes the query string, and the generated rule enables preserve query string, matching Cloudflare's own migration guide for Forwarding URL Page Rules. A trailing * therefore captures the query as part of the last wildcard as well; the builder warns you when that applies so you can test one URL with a query after publishing. The regex form matches http.request.uri.path only, so the query is handled entirely by preserve query string.

Migrating a whole zone off Page Rules? Read Page Rules to Redirect Rules for the deprecation dates and the two migration-guide examples worked through. Coming from another host? The converter turns .htaccess, nginx, Netlify or Vercel redirects into a Cloudflare Bulk Redirects CSV.