soulbird commented on code in PR #9194:
URL: https://github.com/apache/apisix/pull/9194#discussion_r1166445094


##########
apisix/plugins/proxy-rewrite.lua:
##########
@@ -281,25 +288,36 @@ function _M.rewrite(conf, ctx)
         if not str_find(upstream_uri, "?") then
             separator_escaped = true
         end
-
-        local uri, _, err = re_sub(upstream_uri, conf.regex_uri[1],
-                                   conf.regex_uri[2], "jo")
-        if not uri then
-            local msg = "failed to substitute the uri " .. ctx.var.uri ..
-                        " (" .. conf.regex_uri[1] .. ") with " ..
-                        conf.regex_uri[2] .. " : " .. err
-            core.log.error(msg)
-            return 500, {message = msg}
+        local error_msg
+        for i = 1, #conf.regex_uri, 2 do
+            local captures, err = re_match(upstream_uri, conf.regex_uri[i], 
"jo")
+            if err then
+                error_msg = "failed to match the uri " .. ctx.var.uri ..
+                    " (" .. conf.regex_uri[i] .. ") " .. err
+                break
+            end
+            if captures then
+                ctx.proxy_rewrite_regex_uri_captures = captures
+                local uri, _, err = re_sub(upstream_uri,
+                    conf.regex_uri[i], conf.regex_uri[i + 1], "jo")
+                if uri then
+                    upstream_uri = uri
+                else
+                    error_msg = "failed to substitute the uri " .. ngx.var.uri 
..
+                        " (" .. conf.regex_uri[i] .. ") with " ..
+                        conf.regex_uri[i + 1] .. " : " .. err
+                end
+                break
+            end
         end
-
-        local m, err = re_match(upstream_uri, conf.regex_uri[1], "jo")
-        if not m and err then
-            core.log.error("match error in proxy-rewrite plugin, please check: 
", err)
-            return 500
+        if error_msg ~= nil and #error_msg > 0 then
+            core.log.error(error_msg)
+            return 500, { error_msg = error_msg }
         end
-        ctx.proxy_rewrite_regex_uri_captures = m
 
-        upstream_uri = uri
+        if ctx.proxy_rewrite_regex_uri_captures == nil and 
conf.none_match_abort then
+            return 404, { error_msg = "404 Route Not Found" }

Review Comment:
   This error message is wrong, but the rewrite was not successful, not that 
the route did not match successfully



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to