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 2019/12/11 09:48:30 UTC

[GitHub] [incubator-apisix] membphis opened a new issue #961: doc(FAQ): how to use regex to match uri.

membphis opened a new issue #961: doc(FAQ): how to use regex to match uri. 
URL: https://github.com/apache/incubator-apisix/issues/961
 
 
   Currently, only the `path` in a route can be indexed. It supports full matching and prefix matching.
   If you want to support regular matching, you need to use the `vars` of the route.
   
   For example, to match this request: `/api/module/{code}/{param}`
   
   ```lua
   local rule = {
       paths = {"/api/module/*"},
       vars = {"uri", "~~", [[/api/module/{\w+}/{\w+}]]},
   }
   ```
   
   ----
   
   目前路由中只有 path 字段是可以被索引的,它支持全量匹配和前缀匹配。
   如果要支持正则匹配,需要通过路由的 `vars` 实现。
   
   比如要匹配这种请求:`/api/module/{code}/{param}`
   
   在 apisix 中需要这么写:
   
   ```lua
   local rule = {
       paths = {"/api/module/*"},
       vars = {"uri", "~~", [[/api/module/{\w+}/{\w+}]]},
   }
   ```
   

----------------------------------------------------------------
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.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services