You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@apisix.apache.org by GitBox <gi...@apache.org> on 2022/03/08 09:52:09 UTC

[GitHub] [apisix] Horus-K opened a new issue #6547: request help: How to handle query in redirect encode_uri

Horus-K opened a new issue #6547:
URL: https://github.com/apache/apisix/issues/6547


   ### Issue description
   
   ![image](https://user-images.githubusercontent.com/48319268/157209123-4161ef4e-fc14-44c0-9c3b-49a680dc9d88.png)
   The documentation says that query can be processed in regex_uri, how do I use it (when append_query_string is false)
   
   configure:
   regex_uri: ["(.*)/xxxxxx(.*)","https://xxxx.com/vvvvvvvvv$2$is_args$args"]
   error messageļ¼š
   {"error_msg":"failed to check the configuration of plugin redirect err: invalid regex_uri ((.*)\/xxxxxx(.*), https:\/\/xxxx.com\/vvvvvvvvv$2$is_args$args), err:failed to compile the replacement template"}
   
   ### Environment
   
   - apisix version (cmd: `apisix version`): 1.11.0
   - OS (cmd: `uname -a`): centos7.9
   - OpenResty / Nginx version (cmd: `nginx -V` or `openresty -V`):openresty/1.19.9.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:
   - the plugin runner version, if the issue is about a plugin runner (cmd: depended on the kind of runner):
   - luarocks version, if the issue is about installation (cmd: `luarocks --version`):
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao edited a comment on issue #6547: request help: How to handle query in redirect encode_uri

Posted by GitBox <gi...@apache.org>.
shuaijinchao edited a comment on issue #6547:
URL: https://github.com/apache/apisix/issues/6547#issuecomment-1064995944


   @Horus-K  `regex_uri ` not support nginx variables, please look here: https://github.com/apache/apisix/blob/b16c86e24377d19215286c57bff0813a2cfd6c8c/apisix/plugins/redirect.lua#L105-L112
   
   about `append_query_string`  descirbe:
   Redirect query parameters set in `regex_uri` are explicit values rather than variables, enabling `append_query_string` at this time will append the set value to the URL.
   
   refer to this case:
   
   ### Set Route
   ```bash
   curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uri":"/foo/bar/*",
       "plugins":{
           "redirect":{
               "regex_uri": [
                   "(.*)/bar(.*)",
                   "https://www.apache.org/apisix$2?t=gateway"
               ],
               "append_query_string": true
           }
       },
       "upstream":{
           "type":"roundrobin",
           "nodes":{
               "127.0.0.1:1980":1
           }
       }
   }'
   ```
   ### Test Route
   ```bash
   $ curl "http://127.0.0.1:9080/foo/bar/hello?q=hello&a=world" -I
   HTTP/1.1 302 Moved Temporarily
   Date: Fri, 11 Mar 2022 09:44:01 GMT
   Content-Type: text/html
   Content-Length: 110
   Connection: keep-alive
   Location: https://www.apache.org/apisix/hello?t=gateway&q=hello&a=world
   Server: APISIX/2.12.0
   ```
   
   cc @spacewander 


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander closed issue #6547: request help: How to handle query in redirect encode_uri

Posted by GitBox <gi...@apache.org>.
spacewander closed issue #6547:
URL: https://github.com/apache/apisix/issues/6547


   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] spacewander commented on issue #6547: request help: How to handle query in redirect encode_uri

Posted by GitBox <gi...@apache.org>.
spacewander commented on issue #6547:
URL: https://github.com/apache/apisix/issues/6547#issuecomment-1064677924


   @shuaijinchao 
   Would you like to have a look? Thanks!


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



[GitHub] [apisix] shuaijinchao commented on issue #6547: request help: How to handle query in redirect encode_uri

Posted by GitBox <gi...@apache.org>.
shuaijinchao commented on issue #6547:
URL: https://github.com/apache/apisix/issues/6547#issuecomment-1064995944


   `regex_uri ` not support nginx variables, please look here: https://github.com/apache/apisix/blob/b16c86e24377d19215286c57bff0813a2cfd6c8c/apisix/plugins/redirect.lua#L105-L112
   
   about `append_query_string`  descirbe:
   Redirect query parameters set in `regex_uri` are explicit values rather than variables, enabling `append_query_string` at this time will append the set value to the URL.
   
   refer to this case:
   
   ### Set Route
   ```bash
   curl http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
   {
       "uri":"/foo/bar/*",
       "plugins":{
           "redirect":{
               "regex_uri": [
                   "(.*)/bar(.*)",
                   "https://www.apache.org/apisix$2?t=gateway"
               ],
               "append_query_string": true
           }
       },
       "upstream":{
           "type":"roundrobin",
           "nodes":{
               "127.0.0.1:1980":1
           }
       }
   }'
   ```
   ### Test Route
   ```bash
   $ curl "http://127.0.0.1:9080/foo/bar/hello?q=hello&a=world" -I
   HTTP/1.1 302 Moved Temporarily
   Date: Fri, 11 Mar 2022 09:44:01 GMT
   Content-Type: text/html
   Content-Length: 110
   Connection: keep-alive
   Location: https://www.apache.org/apisix/hello?t=gateway&q=hello&a=world
   Server: APISIX/2.12.0
   ```
   


-- 
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: notifications-unsubscribe@apisix.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org