This is the public channel for all developers in the world. Please use
English.
*Question*:
*Chinese*: 我需要将 http://test.com/abc/index.html 的地址转发到后端,rewrite为
http://test.com/xyz/index.html, 请问这个需要怎么配置
我试了nignx的rewrite写法,没有成功
*English*: I want to forward http://test.com/abc/index.html to the
backend and rewrite the Uri to http://test.com/xyz/index.html .
How can I implement this?
*Answer*:
You can use `proxy-rewrite` plugin:
Add a route:
curl http://127.0.0.1:9080/apisix/admin/routes/1 -X PUT -d '
{
"uri": "/abc/*",
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/abc/(.*)", "/xyz/$1"]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"127.0.0.1:1980": 1
}
}
}'
$ curl http://127.0.0.1:9080/abc/iimm -i
HTTP/1.1 200 OK
Content-Type: text/plain
Transfer-Encoding: chunked
Connection: keep-alive
Server: APISIX web server
Date: Thu, 27 Feb 2020 12:44:08 GMT
Cache-Control: max-age=10
/xyz/iimm # the response is the upstream Uir
On Thu, Feb 27, 2020 at 8:20 PM 高生 <[email protected]> wrote:
> 咨询:
> 我需要将 http://test.com/abc/index.html
> <http://test.com/abc/index.html>的地址转发到后端,rewrite为
> http://test.com/xyz/index.html, <http://test.com/xyz/index.html,
> >请问这个需要怎么配置
> 我试了nignx的rewrite写法,没有成功
>
>
> 谢谢
--
*MembPhis*
My github: https://github.com/membphis
Apache APISIX: https://github.com/apache/incubator-apisix