Closed GloryAndDream closed 4 months ago
Your regex is wrong.
Example:
curl http://127.0.0.1:9180/apisix/admin/routes/1 \
-H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
{
"methods": ["GET"],
"uri": "/*",
"plugins": {
"proxy-rewrite": {
"regex_uri": ["^/(machine|pay)(/.*)", "/$2"]
}
},
"upstream": {
"type": "roundrobin",
"nodes": {
"httpbin.org": 1
}
}
}'
Your regex is wrong.
Example:
curl http://127.0.0.1:9180/apisix/admin/routes/1 \ -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d ' { "methods": ["GET"], "uri": "/*", "plugins": { "proxy-rewrite": { "regex_uri": ["^/(machine|pay)(/.*)", "/$2"] } }, "upstream": { "type": "roundrobin", "nodes": { "httpbin.org": 1 } } }'
I tried you regexp, still not working
http://api-test.xxx.com/machine/health
Whitelabel Error Page
This application has no explicit mapping for /error, so you are seeing this as a fallback.
Fri Apr 07 21:56:08 CST 2023
There was an unexpected error (type=Not Found, status=404).
http://api-test.xxx.com/machine
{"error_msg":"404 Route Not Found"}
seems only first part of path goes to controller, by the way, the API is built on springboot, the path /machine/health is configured
What part of the uri do you want to extract? In my code, I assume you need to get the second part, that is, for /machine/health
, you need /health
. If that's not your case, you need to configure the target uri you need for the upstream server. In your output, the request http://api-test.xxx.com/machine/health will be changed to http://api-test.xxx.com/health, and it's obvious it's sent to the controller server, but gets 404 finally.
Anyways, you need to debug your regexp to fit your need.
"^/(machine|pay)(/.*)", "/$2"
Yes, I need to extract second part, but I tried this regexp "^/machine(/.*)", "/$2" , it worked fine, the url http://api-test.xxx.com/machine/health is accessible
it seems the plugin can't handle with symbol "|" , don't know it is a bug or not
|
must be quoted with (
. That's not a bug, it's regex usage issue.
What's your question? I'm really confused.
However, when I deploy this configurations, it can only match paths begin with /machine/* , not the /pay/xxx
or
http://api-test.xxx.com/machine
{"error_msg":"404 Route Not Found"}`
Anyways, the regex obeys the pcre regex standard, please change your regex to fit your need.
I need to match below urls: e.g.
http://api-test.xxx.com/machine/aaa
http://api-test.xxx.com/pay/bbb
however, I can't find the correct regexp to get what I need with plugin proxy-rewite
anyone can help me with correct regex string?
This issue has been marked as stale due to 350 days of inactivity. It will be closed in 2 weeks if no further activity occurs. If this issue is still relevant, please simply write any comment. Even if closed, you can still revive the issue at any time or discuss it on the dev@apisix.apache.org list. Thank you for your contributions.
This issue has been closed due to lack of activity. If you think that is incorrect, or the issue requires additional review, you can revive the issue at any time.
Description
I want to proxy-rewrite support multiple paths, but even I got regexp correct, it didn't work for both paths:
e.g. regexp is below:
*^/machine|pay(/|$)(.)**
can match below paths:
/machine/tests /machine /machine/ /pay/testset /pay/
However, when I deploy this configurations, it can only match paths begin with **/machine/* , not the /pay/xxx**
Is there a solution or not?
Environment
apisix version
):uname -a
):openresty -V
ornginx -V
):curl http://127.0.0.1:9090/v1/server_info
):luarocks --version
):