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.
- Go to Domains → select the domain → Origin Rewrite tab.

- Click Add Rule to open the rule form.
- 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.
- (Optional) Turn Enabled on/off for each rule — a separate toggle, independent of the section's On/Off switch.
- 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:
| Field | Meaning | Values | Default | Notes |
|---|---|---|---|---|
| On/Off switch (corner of the section) | Turns all origin rewrite on/off — On = creates the configuration, Off = deletes it | Switch | Off (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/off | Off | By default, //... paths return 400 (SSRF protection). Turn on only for legacy clients that send // |
Each rule:
| Field | Meaning | Values | Default | Notes |
|---|---|---|---|---|
| Rule Name | Rule name | ≤128 characters, required | — | — |
| Enabled | Turns the rule on/off | On/off | On | — |
| Priority | Priority (intent) | -1000..10000 | 0 (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 Pattern | Path pattern to match | String | Empty (= matches every path) | If Match Type = regex, ≤500 characters + a valid regex |
| Match Type | How the Path Pattern is compared | prefix / exact / suffix / contains / wildcard / regex | prefix | Also affects how the path is rewritten — see the pitfall in Order of evaluation |
| Match Hostnames | Restricts the rule by hostname (OR) | ≤20, operators equals/contains/starts_with/ends_with/wildcard/regex | Empty (= every host) | Matches the request's host |
| Origin URLs | Set of target origins | ≥1 URL, each ≤2048, http(s):// | — | Private/loopback origins are not allowed (SSRF protection) |
| Weights | Weight/priority order per URL | Length = number of URLs, each 1..1000 | — | Used only when Selector = weighted/failover |
| Selector | Origin selection algorithm | round_robin / failover / weighted_round_robin | round_robin | — |
| Host Header | Host sent to the origin | ≤253, printable characters | Empty (derived from the URL) | — |
| TLS to Origin | Enables TLS to the origin | On/off | Off | On with an http:// URL → 400 |
| Skip Cert Verification | Skips origin certificate verification | On/off | Off (verification enabled) | On = MITM risk |
| SNI Override | SNI in the handshake to the origin | Hostname | Empty | Valid only when TLS to Origin = on |
| Protocol | Protocol to the origin | h1.1 / h2 | h1.1 | — |
| Origin Headers | Headers added/overridden when sending to the origin | ≤50 | — | CR/LF characters are blocked |
| Rewrite Path To | Rewrites the path sent to the origin | Starts 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 |
| Conditions | Additional 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 URLshttps://api-backend:443 - Result:
GET /api/users→ the originapi-backend:443receives/v2/users(the/apiprefix 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 URLshttps://origin:443 - Result:
GET /old-endpoint→ the origin receives/new-endpoint. - Check:
curl/old-endpointand check the origin log.
Example 3 — Route by hostname (no path rewrite).
- Match Hostnames
[equals: img.example.com]· leave Path Pattern empty · Origin URLshttps://image-origin:443· Host Headerimage-origin - Result: every request to the host
img.example.comgoes toimage-originwithHost: 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: withsuffix/contains/wildcard/regex, the Rewrite Path To value replaces the entire path (not just the matched part). For example, Match Typecontains+ Path Patternapi+ Rewrite/zmeans/a/api/b→ the origin receives/z. Useprefix/exactif 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
| Symptom | Common cause | Fix |
|---|---|---|
| The rule does not run | The section's On/Off switch is Off (not configured), the rule is disabled, or Origin URLs is empty | Switch On; turn on the rule's Enabled; add at least 1 Origin URL |
| The origin receives a truncated/wrong path | Match Type ≠ prefix/exact, so Rewrite replaces the entire path | Use prefix/exact, or adjust Rewrite Path To |
| Save returns 400 (private/loopback) | The Origin URL points to an internal/loopback IP | Use a valid public origin |
| Save returns 400 when TLS is on | The URL is http:// but TLS to Origin is on | Use https:// for the origin, or turn off TLS |
| Save returns 400 "length must match urls" | Weights do not have the same length as Origin URLs | Match the number of weights to the number of URLs (each weight 1–1000) |
| Old content is still served after changing rules | The cache was built from the old routing | Purge the domain after changing rules |
FAQ
- Why does changing
prioritychange the result? The edge matches bypriority(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→/v2means/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).