Skip to content

networking: add prefix_rewrite and uri_regex_rewrite to HTTPRedirect#3708

Open
liamawhite wants to merge 3 commits into
istio:masterfrom
liamawhite:feature/redirect-prefix-rewrite
Open

networking: add prefix_rewrite and uri_regex_rewrite to HTTPRedirect#3708
liamawhite wants to merge 3 commits into
istio:masterfrom
liamawhite:feature/redirect-prefix-rewrite

Conversation

@liamawhite
Copy link
Copy Markdown
Member

Summary

HTTPRedirect.uri performs a full path replacement and has no prefix-aware variant. Envoy's RedirectAction has supported prefix_rewrite and regex_rewrite for years, but Istio has never exposed them, making it impossible to perform redirects that preserve the path suffix (e.g. example.com/foo/barfoo.example.com/bar).

This was requested in istio/istio#47500, istio/istio#47777, and istio/istio#52521, all of which were closed as stale.

This PR adds two new fields to HTTPRedirect inside a oneof path_rewrite_specifier:

  • prefix_rewrite — replaces the matched route prefix, leaving the rest of the path intact. The route must use a prefix URI match.
  • uri_regex_rewrite — RE2 regex rewrite with capture group substitution (reuses the existing RegexRewrite message).

Both are mutually exclusive with the existing uri field (enforced by validation in istio/istio). The legacy uri field is unchanged.

Examples

Strip a prefix and change host (/foo/barfoo.example.com/bar):

redirect:
  authority: foo.example.com
  prefix_rewrite: /
  redirectCode: 301

Replace a prefix (/foo/bar/baz/bar):

redirect:
  prefix_rewrite: /baz
  redirectCode: 301

Regex rewrite (/api/v1/users/users):

redirect:
  uri_regex_rewrite:
    match: "^/api/v1(/.*)$"
    rewrite: "\\1"
  redirectCode: 302

Related

Extends HTTPRedirect to support prefix-aware path manipulation on
redirect responses, exposing Envoy's existing prefix_rewrite and
regex_rewrite capabilities in RedirectAction.

Previously, HTTPRedirect.uri replaced the entire path regardless of
the route match type. This adds two new mutually-exclusive fields:

- prefix_rewrite: replaces the matched route prefix with the given
  value, enabling /foo/bar -> /baz/bar style redirects
- uri_regex_rewrite: rewrites the path using RE2 regex with capture
  group substitution for complex transformations

Both are mutually exclusive with the existing uri field. Validation
is enforced in the istio/istio control plane.
@liamawhite liamawhite requested a review from a team as a code owner May 16, 2026 06:38
@istio-policy-bot
Copy link
Copy Markdown

🤔 🐛 You appear to be fixing a bug in Go code, yet your PR doesn't include updates to any test files. Did you forget to add a test?

Courtesy of your friendly test nag.

@istio-testing istio-testing added the size/M Denotes a PR that changes 30-99 lines, ignoring generated files. label May 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/M Denotes a PR that changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants