docs(proxy-rewrite): fix regex_uri example#13283
docs(proxy-rewrite): fix regex_uri example#13283xuruidong wants to merge 4 commits intoapache:masterfrom
Conversation
| | 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`. | |
There was a problem hiding this comment.
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.
Description
Which issue(s) this PR fixes:
Fixes #
Checklist