apisix icon indicating copy to clipboard operation
apisix copied to clipboard

request help: how to use regex in redirect plugin?

Open JanLi-air opened this issue 5 years ago • 4 comments

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 -V or openresty -V): 1.19.3.1
  • etcd version, if have (cmd: run curl http://127.0.0.1:9090/v1/server_info to get the info from server-info API):
  • apisix-dashboard version, if have:
  • luarocks version, if the issue is about installation (cmd: luarocks --version):

JanLi-air avatar Apr 27 '21 09:04 JanLi-air

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

tzssangglass avatar Apr 27 '21 10:04 tzssangglass

I need 302 redirect, since FE needs the redirected url

JanLi-air avatar Apr 28 '21 02:04 JanLi-air

@JanLi-air Currently the redirect plugin cannot fetch regex capture group from the original URI, would you like to optimize it?

tokers avatar Apr 28 '21 02:04 tokers

Surpassed by #4229

spacewander avatar May 14 '21 01:05 spacewander