This is an automated email from the ASF dual-hosted git repository.

spacewander pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new 2744a99  docs: add route uri regular matching in the FAQ doc (#3881)
2744a99 is described below

commit 2744a9947250b83c5dab8ca7925ab6947f735c82
Author: Yuelin Zheng <2226815...@qq.com>
AuthorDate: Tue Mar 23 09:08:08 2021 +0800

    docs: add route uri regular matching in the FAQ doc (#3881)
---
 docs/en/latest/FAQ.md | 36 ++++++++++++++++++++++++++++++++++++
 docs/zh/latest/FAQ.md | 36 ++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)

diff --git a/docs/en/latest/FAQ.md b/docs/en/latest/FAQ.md
index eb5e917..1ab0b3b 100644
--- a/docs/en/latest/FAQ.md
+++ b/docs/en/latest/FAQ.md
@@ -404,3 +404,39 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1  -H 
'X-API-KEY: edd1c9f03433
     }
 }'
 ```
+
+## How to use route `uri` for regular matching
+
+The regular matching of uri is achieved through the `vars` field of route.
+
+```shell
+curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "uri": "/*",
+    "vars": [
+        ["uri", "~~", "^/[a-z]+$"]
+    ],
+    "upstream": {
+            "type": "roundrobin",
+            "nodes": {
+                "127.0.0.1:1980": 1
+            }
+    }
+}'
+```
+
+Test request:
+
+```shell
+# The uri matched successfully
+$ curl http://127.0.0.1:9080/hello -i
+HTTP/1.1 200 OK
+...
+
+# The uri match failed
+curl http://127.0.0.1:9080/12ab -i
+HTTP/1.1 404 Not Found
+...
+```
+
+In route, we can achieve more condition matching by combining `uri` with 
`vars` field. For more details of using `vars`, please refer to 
[lua-resty-expr](https://github.com/api7/lua-resty-expr).
diff --git a/docs/zh/latest/FAQ.md b/docs/zh/latest/FAQ.md
index 54ec6a1..98af1b5 100644
--- a/docs/zh/latest/FAQ.md
+++ b/docs/zh/latest/FAQ.md
@@ -352,3 +352,39 @@ curl -i http://127.0.0.1:9180/apisix/admin/routes/1  -H 
'X-API-KEY: edd1c9f03433
     }
 }'
 ```
+
+## route 的 `uri` 如何进行正则匹配
+
+这里通过 route 的 `vars` 字段来实现 uri 的正则匹配。
+
+```shell
+curl -i http://127.0.0.1:9080/apisix/admin/routes/1 -H 'X-API-KEY: 
edd1c9f034335f136f87ad84b625c8f1' -X PUT -d '
+{
+    "uri": "/*",
+    "vars": [
+        ["uri", "~~", "^/[a-z]+$"]
+    ],
+    "upstream": {
+            "type": "roundrobin",
+            "nodes": {
+                "127.0.0.1:1980": 1
+            }
+    }
+}'
+```
+
+测试请求:
+
+```shell
+# uri 匹配成功
+$ curl http://127.0.0.1:9080/hello -i
+HTTP/1.1 200 OK
+...
+
+# uri 匹配失败
+curl http://127.0.0.1:9080/12ab -i
+HTTP/1.1 404 Not Found
+...
+```
+
+在 route 中,我们可以通过 `uri` 结合 `vars` 字段来实现更多的条件匹配,`vars` 的更多使用细节请参考 
[lua-resty-expr](https://github.com/api7/lua-resty-expr)。

Reply via email to