Skip to content

docs(proxy-rewrite): fix regex_uri example#13283

Open
xuruidong wants to merge 4 commits intoapache:masterfrom
xuruidong:patch-1
Open

docs(proxy-rewrite): fix regex_uri example#13283
xuruidong wants to merge 4 commits intoapache:masterfrom
xuruidong:patch-1

Conversation

@xuruidong
Copy link
Copy Markdown
Contributor

Description

Which issue(s) this PR fixes:

Fixes #

Checklist

  • I have explained the need for this PR and the problem it solves
  • I have explained the changes or the new features added to this PR
  • I have added tests corresponding to this change
  • I have updated the documentation to reflect this change
  • I have verified that this change is backward compatible (If not, please discuss on the APISIX mailing list first)

@dosubot dosubot Bot added size:XS This PR changes 0-9 lines, ignoring generated files. doc Documentation things labels Apr 23, 2026
Comment thread docs/en/latest/plugins/proxy-rewrite.md Outdated
| uri | string | False | | | New Upstream URI path. Value supports [NGINX variables](https://nginx.org/en/docs/http/ngx_http_core_module.html). For example, `$arg_name`. |
| method | string | False | | ["GET", "POST", "PUT", "HEAD", "DELETE", "OPTIONS","MKCOL", "COPY", "MOVE", "PROPFIND", "PROPFIND","LOCK", "UNLOCK", "PATCH", "TRACE"] | HTTP method to rewrite requests to use. |
| regex_uri | array[string] | False | | | Regular expressions used to match the URI path from client requests and compose a new Upstream URI path. When both `uri` and `regex_uri` are configured, `uri` has a higher priority. The array should contain one or more **key-value pairs**, with the key being the regular expression to match URI against and value being the new Upstream URI path. For example, with `["^/iresty/(. *)/(. *)", "/$1-$2", ^/theothers/*", "/theothers"]`, if a request is originally sent to `/iresty/hello/world`, the Plugin will rewrite the Upstream URI path to `/iresty/hello-world`; if a request is originally sent to `/theothers/hello/world`, the Plugin will rewrite the Upstream URI path to `/theothers`. |
| regex_uri | array[string] | False | | | Regular expressions used to match the URI path from client requests and compose a new Upstream URI path. When both `uri` and `regex_uri` are configured, `uri` has a higher priority. The array should contain one or more **key-value pairs**, with the key being the regular expression to match URI against and value being the new Upstream URI path. For example, with `["^/iresty/(.*)/(.*)", "/$1-$2", "^/theothers/*", "/theothers"]`, if a request is originally sent to `/iresty/hello/world`, the Plugin will rewrite the Upstream URI path to `/hello-world`; if a request is originally sent to `/theothers/hello/world`, the Plugin will rewrite the Upstream URI path to `/theothers`. |
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The key evidence is in apisix/plugins/proxy-rewrite.lua:294-308: after regex_uri matches, APISIX runs re_sub(upstream_uri, pattern, replacement, "jo") on the whole upstream URI. That means only the matched part is replaced, while any unmatched suffix is preserved. The existing test t/plugin/proxy-rewrite.t:572-602 shows this behavior as well: when the pattern ^/test/(.*)/(.*)/(.*) covers the full path, /test/plugin/proxy/rewrite becomes exactly /plugin_proxy_rewrite.

In this PR, the docs still use "^/theothers/*" -> "/theothers" and say /theothers/hello/world will be rewritten to /theothers. That pattern does not consume the trailing hello/world segment, so it cannot produce the documented result. In other words, this revision fixes the first wrong example, but the second wrong example still remains in both the English and Chinese docs.

Please update the second example to a pattern that consumes the remaining path as well (for example, if the intent is to collapse any /theothers/... request to /theothers, something like ^/theothers(/.*)?$ would be closer to the actual behavior), and then I can take another quick look.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc Documentation things size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants