You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: content/ngf/traffic-management/advanced-routing.md
+62-1Lines changed: 62 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -11,7 +11,7 @@ Learn how to deploy multiple applications and HTTPRoutes with request conditions
11
11
12
12
## Overview
13
13
14
-
In this guide we will configure advanced routing rules for multiple applications. These rules will showcase request matching by path, headers, query parameters, and method. For an introduction to exposing your application, we recommend that you follow the [basic guide]({{< ref "/ngf/traffic-management/basic-routing.md" >}}) first.
14
+
In this guide we will configure advanced routing rules for multiple applications. These rules will showcase request matching by path (including prefix, exact, and regex patterns), headers, query parameters, and method. For an introduction to exposing your application, we recommend that you follow the [basic guide]({{< ref "/ngf/traffic-management/basic-routing.md" >}}) first.
15
15
16
16
The following image shows the traffic flow that we will be creating with these rules.
17
17
@@ -321,6 +321,67 @@ Server name: tea-post-b59b8596b-g586r
321
321
322
322
This request should receive a response from the `tea-post` pod. Any other type of method, such as PATCH, will result in a `404 Not Found` response.
323
323
324
+
## Path matching types
325
+
326
+
NGINX Gateway Fabric supports three types of path matching:
327
+
328
+
-**PathPrefix**: Matches based on a URL path prefix split by `/`. For example, `/coffee` matches `/coffee`, `/coffee/`, and `/coffee/latte`.
329
+
-**Exact**: Matches the exact path in the request. For example, `/coffee` matches only `/coffee`.
330
+
-**RegularExpression**: Matches based on RE2-compatible regular expressions. For example, `/coffee/[a-z]+` matches `/coffee/latte` and `/coffee/mocha` but not `/coffee/123`.
331
+
332
+
{{< call-out "note" >}} Regular expression path matching uses the RE2 syntax. Patterns are automatically anchored to the beginning of the path. {{< /call-out >}}
333
+
334
+
### Example: Using regex path matching
335
+
336
+
To route requests based on regex patterns in the path, use `type: RegularExpression`:
337
+
338
+
```yaml
339
+
kubectl apply -f - <<EOF
340
+
apiVersion: gateway.networking.k8s.io/v1
341
+
kind: HTTPRoute
342
+
metadata:
343
+
name: coffee-regex
344
+
spec:
345
+
parentRefs:
346
+
- name: cafe
347
+
hostnames:
348
+
- cafe.example.com
349
+
rules:
350
+
- matches:
351
+
- path:
352
+
type: RegularExpression
353
+
value: /coffee/[a-z]+
354
+
backendRefs:
355
+
- name: coffee-v1-svc
356
+
port: 80
357
+
EOF
358
+
```
359
+
360
+
This configuration routes requests like `/coffee/latte` or `/coffee/mocha` to the `coffee-v1-svc` backend, while paths like `/coffee/123` or `/coffee` will not match.
0 commit comments