apisix
apisix copied to clipboard
request help: how to use regex in redirect plugin?
Issue description
I need to configure route which implement similar logic as this nginx config:
location ~ ^/foo/bar(/.*)? {
return 302 $scheme://$host/app/bar$1$is_args$args;
}
But in redirect plugin I can only use $uri, which will contains /foo which I want to remove in the redirct locaton.
Environment
- apisix version (cmd:
apisix version): 2.0 - OS (cmd:
uname -a): Linux - OpenResty / Nginx version (cmd:
nginx -Voropenresty -V): 1.19.3.1 - etcd version, if have (cmd: run
curl http://127.0.0.1:9090/v1/server_infoto get the info from server-info API): - apisix-dashboard version, if have:
- luarocks version, if the issue is about installation (cmd:
luarocks --version):
you can use proxy-rewrite plugin to do this, config as
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/foo/(.*)","/$1"]
}
}
This will change the url of the request from /foo/a/b/c to /a/b/c
I need 302 redirect, since FE needs the redirected url
@JanLi-air Currently the redirect plugin cannot fetch regex capture group from the original URI, would you like to optimize it?
Surpassed by #4229