HTTPProxy.
URL rewriting is useful when:
- Your public API path structure differs from your backend’s internal paths
- You want to strip a path prefix before forwarding (e.g.,
/api/v1/users→/users) - You need to replace the full path for a specific route
- You need to rewrite the hostname the backend sees (separate from
Hostheader modification)
Overview
TheURLRewrite filter modifies the path and/or hostname of the forwarded request. Unlike RequestHeaderModifier, which sets arbitrary headers, URLRewrite is purpose-built for path and authority rewriting and is the recommended approach for path manipulation.
At a high level, this setup:
- Matches requests on a path prefix
- Rewrites the path before forwarding to the backend
- The client sees no change to the URL
Prerequisites
datumctlinstalled and authenticated- A valid Project
Configuration Steps
Step 1: Set Variables
Windows (PowerShell)
macOS / Linux
Step 2: Apply URL Rewrite Configuration
This example strips the/api prefix. Requests to /api/users are forwarded to the backend as /users.
ReplacePrefixMatch must be paired with a PathPrefix match on the same prefix — mixing match types will cause the route to be rejected.
Windows (PowerShell)
macOS / Linux
Path Rewrite Options
Replace Prefix
Replaces the matched prefix and preserves the rest of the path.
The match rule’s
path.value and replacePrefixMatch must use the same prefix. Using ReplacePrefixMatch with an Exact or RegularExpression match will cause the route to be rejected.
Replace Full Path
Replaces the entire path, ignoring what was matched.
Useful for mapping multiple public paths to a single backend endpoint.
Hostname Rewrite
Rewrites the authority (hostname) the backend sees without changing request headers separately.hostname and path can be combined in a single URLRewrite filter.
Verification
httpbin.org/anything reflects the path received by the upstream. Use it to confirm the rewrite before pointing at a real backend.
Update your rule’s backends[].endpoint to https://httpbin.org temporarily, then:
url field in the response — it should show /users, not /api/users.
Cleanup
Windows (PowerShell)
macOS / Linux
Troubleshooting
Best Practices
- Use
ReplacePrefixMatchfor stripping versioned path prefixes (e.g.,/v1,/api) - Use
ReplaceFullPathwhen mapping multiple routes to a single backend endpoint - Test rewrites with
httpbin.org/anythingbefore switching to a production backend — it reflects the exact path the upstream receives - Keep match prefix and
replacePrefixMatchprefix consistent to avoid rejected routes
Summary
- URL path rewriting uses
type: URLRewritewith apathblock path.typeis required:ReplacePrefixMatchorReplaceFullPathReplacePrefixMatchmust be paired with aPathPrefixmatch on the same prefixhostnamecan be set alongsidepathin the same filter- The rewrite is transparent to the client — only the upstream sees the modified path