Skip to main content

Origin Rewrite — path rewriting & routing to the origin

This section uses an On/Off switch in the top corner (turns all of Origin Rewrite on/off for the domain). Off = delete the domain's entire origin rewrite configuration (all rules).

Origin Rewrite lets you define rules: when a request matches (by path + hostname + conditions), the edge routes it to a different set of origin URLs and/or rewrites the path sent to the origin — with per-rule settings: host header, protocol (h1.1/h2), TLS to the origin, SNI, load balancing choice (selector), weights, and custom origin headers. In effect, this is a "per-path upstream override".

Use this when: splitting traffic by path to a different backend, remapping paths (/api/ → /v2/), migrating the origin by prefix, or A/B testing origins. Example: /api/* needs to go to a separate backend cluster while everything else keeps the same origin — set up one origin rewrite rule for /api/.

Before you start​

  • The domain has been added, points to VNIS, and has an Origin/Upstream configured.
  • You know the target origin (URL, and whether it needs its own TLS/host header).

How to configure​

This section uses an On/Off switch in the top corner: On = create and apply the configuration (saved immediately); Off = delete all of the domain's origin rewrite rules. The rules are shown even when Off — add/edit them first, then switch On.

  1. Go to Domains → select the domain → Origin Rewrite tab. Go to Domains → select the domain → Origin Rewrite tab
  2. Click Add Rule to open the rule form.
  3. Set the Rule Name, Path Pattern + Match Type, and Origin URLs; (optional) Rewrite Path To, Match Hostnames, Host Header, TLS to Origin, Selector/Weights, Conditions.
  4. (Optional) Turn Enabled on/off for each rule — a separate toggle, independent of the section's On/Off switch.
  5. Turn on the On switch in the top corner of the section. For later changes, click Save (shown only when On and there are unsaved changes).

Configuration fields​

Section level:

FieldMeaningValuesDefaultNotes
On/Off switch (corner of the section)Turns all origin rewrite on/off — On = creates the configuration, Off = deletes itSwitchOff (not configured)Off = all rules are skipped and the configuration is deleted (to turn it back on, you have to configure it again); you cannot switch On while a rule has errors
Collapse leading //Collapses paths starting with // to /On/offOffBy default, //... paths return 400 (SSRF protection). Turn on only for legacy clients that send //

Each rule:

FieldMeaningValuesDefaultNotes
Rule NameRule name≤128 characters, required——
EnabledTurns the rule on/offOn/offOn—
PriorityPriority (intent)-1000..100000 (the UI suggests 100)Lower numbers match first (first match). Rules with the same priority keep the order in which they were added — see Order of evaluation
Path PatternPath pattern to matchStringEmpty (= matches every path)If Match Type = regex, ≤500 characters + a valid regex
Match TypeHow the Path Pattern is comparedprefix / exact / suffix / contains / wildcard / regexprefixAlso affects how the path is rewritten — see the pitfall in Order of evaluation
Match HostnamesRestricts the rule by hostname (OR)≤20, operators equals/contains/starts_with/ends_with/wildcard/regexEmpty (= every host)Matches the request's host
Origin URLsSet of target origins≥1 URL, each ≤2048, http(s)://—Private/loopback origins are not allowed (SSRF protection)
WeightsWeight/priority order per URLLength = number of URLs, each 1..1000—Used only when Selector = weighted/failover
SelectorOrigin selection algorithmround_robin / failover / weighted_round_robinround_robin—
Host HeaderHost sent to the origin≤253, printable charactersEmpty (derived from the URL)—
TLS to OriginEnables TLS to the originOn/offOffOn with an http:// URL → 400
Skip Cert VerificationSkips origin certificate verificationOn/offOff (verification enabled)On = MITM risk
SNI OverrideSNI in the handshake to the originHostnameEmptyValid only when TLS to Origin = on
ProtocolProtocol to the originh1.1 / h2h1.1—
Origin HeadersHeaders added/overridden when sending to the origin≤50—CR/LF characters are blocked
Rewrite Path ToRewrites the path sent to the originStarts with /, no ?, no ..Empty (keeps the original path)Has effect only when the Path Pattern is not empty — see the pitfall in Order of evaluation
ConditionsAdditional AND conditions≤20; fields url_path,query_string,method,hostname,user_agent,cookie,origin,via,ip_source——

Limit: at most 100 rules per domain.

Configuration examples​

Rules are matched by priority (lower numbers first; the first matching rule wins). All conditions in a rule must match together (AND).

Example 1 — Split /api/* to a separate backend and remap it to /v2/.

  • Match Type prefix · Path Pattern /api · Rewrite Path To /v2 · Origin URLs https://api-backend:443
  • Result: GET /api/users → the origin api-backend:443 receives /v2/users (the /api prefix is replaced with /v2, keeping the rest of the path). The original query is kept.
  • Check: look at the backend origin's log to confirm it received /v2/users.

Example 2 — Replace a fixed path entirely.

  • Match Type exact · Path Pattern /old-endpoint · Rewrite Path To /new-endpoint · Origin URLs https://origin:443
  • Result: GET /old-endpoint → the origin receives /new-endpoint.
  • Check: curl /old-endpoint and check the origin log.

Example 3 — Route by hostname (no path rewrite).

  • Match Hostnames [equals: img.example.com] · leave Path Pattern empty · Origin URLs https://image-origin:443 · Host Header image-origin
  • Result: every request to the host img.example.com goes to image-origin with Host: image-origin; the path is unchanged (no Rewrite Path To).
  • Check: send a request with the matching host and confirm the target origin + Host header.

Order of evaluation​

  • The section's On/Off switch = whether the configuration exists: Off = delete all origin rewrite rules; this is different from the per-rule Enabled toggle (which only temporarily turns one rule on/off, without deleting it).
  • The edge matches rules by priority: lower numbers match first. If 2 rules both match → the rule with the lower priority wins. Give specific rules a lower priority.
  • Rewrite Path pitfall when Match Type ≠ prefix/exact: with suffix/contains/wildcard/regex, the Rewrite Path To value replaces the entire path (not just the matched part). For example, Match Type contains + Path Pattern api + Rewrite /z means /a/api/b → the origin receives /z. Use prefix/exact if you want to keep the rest of the path.
  • Rewrite Path applies only when both Path Pattern and Rewrite Path To are not empty. An empty Path Pattern + a Rewrite Path To → no rewrite (but the upstream can still be overridden if the rule matches).
  • An origin rewrite rule overrides the domain's upstream when it matches; if no rule matches → the default upstream is used. The retry policy is inherited from the domain's Upstream.
  • After adding/changing a rule tied to a hostname, PURGE the domain's cache — to avoid serving cached copies built from the old routing.

Troubleshooting​

SymptomCommon causeFix
The rule does not runThe section's On/Off switch is Off (not configured), the rule is disabled, or Origin URLs is emptySwitch On; turn on the rule's Enabled; add at least 1 Origin URL
The origin receives a truncated/wrong pathMatch Type ≠ prefix/exact, so Rewrite replaces the entire pathUse prefix/exact, or adjust Rewrite Path To
Save returns 400 (private/loopback)The Origin URL points to an internal/loopback IPUse a valid public origin
Save returns 400 when TLS is onThe URL is http:// but TLS to Origin is onUse https:// for the origin, or turn off TLS
Save returns 400 "length must match urls"Weights do not have the same length as Origin URLsMatch the number of weights to the number of URLs (each weight 1–1000)
Old content is still served after changing rulesThe cache was built from the old routingPurge the domain after changing rules

FAQ​

  • Why does changing priority change the result? The edge matches by priority (lower numbers first). Change the priority to put specific rules first.
  • How does Rewrite Path work with prefix? It strips the matched prefix, then joins Rewrite Path To + the remaining part (keeping the rest of the path). For example, /api → /v2 means /api/x → /v2/x.
  • Do I need to re-cache after changing rules? You should Purge the domain, especially for rules tied to a hostname.
  • How is this different from Redirects? Redirects return a 3xx to the client (the client changes URL); Origin Rewrite silently changes where the edge fetches content from (the client does not see a URL change).