URI path matching
Specify exact, prefix, or regex criteria to match against the targeted path.
Match the targeted path of an incoming request against specific path criteria. For example, if you specify path criteria in a route table for service B, a request from service A in your mesh to service B must use that path criteria in order for the request to be routed. For other methods of request matching, see Match incoming requests.
The following URI matching criteria are supported for route tables.
Matching method | Description | Example path matcher | Example request matches |
---|---|---|---|
Exact | Route requests only to the path that exactly matches the specified string. | /myapp | /myapp |
Prefix | Route requests to any paths that contain the specified path prefix. | /myapp | /myapp/foo , /myapp/bar |
Regex | Route requests to any paths that match an ECMAScript-style regular expression. | \/v.*\/myapp | /v1/myapp , /v2/myapp |
Suffix matching is not currently supported.
For more information, see the Gloo Mesh Enterprise API docs for route tables and for request matching.
Exact matching
Route requests only to the path that exactly matches the specified string.
In a RouteTable resource, add the following matchers
section to your route. Note that you can optionally include the ignoreCase: true
option to make matching case-insensitive.
...
http:
- matchers:
- uri:
exact: <path>
ignoreCase: <true|false>
...
In the following example, exact: /myapp
indicates that only requests that are exactly to myapp.global.svc.cluster.local/myapp
are forwarded to the myapp
service. Because the ignoreCase: true
line is commented out, requests to paths such as myapp.global.svc.cluster.local/MYapp
or myapp.global.svc.cluster.local/myApp
are not forwarded.
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
name: exact-match
namespace: global
spec:
hosts:
- 'myapp.global.svc.cluster.local'
http:
# Match only requests to exactly 'myapp.global.svc.cluster.local/myapp'
- matchers:
- uri:
exact: /myapp
#ignoreCase: true
forwardTo:
destinations:
- ref:
name: myapp
namespace: global
cluster: ${REMOTE_CLUSTER1}
port:
number: 8090
kind: SERVICE
Prefix matching
Route requests to any paths that contain the specified path prefix.
In a RouteTable resource, add the following matchers
section to your route. Note that you can optionally include the ignoreCase: true
option to make matching case-insensitive.
...
http:
- matchers:
- uri:
prefix: <path>
ignoreCase: <true|false>
...
In this example, prefix: /myapp
indicates that any requests that contain the /myapp
path prefix, such as requests to myapp.global.svc.cluster.local/myapp/foo
and myapp.global.svc.cluster.local/myapp/bar
, are forwarded to the myapp
service. Because the example includes ignoreCase: true
, requests to paths such as myapp.global.svc.cluster.local/MYapp/foo
and myapp.global.svc.cluster.local/myApp/bar
are also forwarded.
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
name: prefix-match
namespace: global
spec:
hosts:
- 'myapp.global.svc.cluster.local'
http:
# Match any requests to 'myapp.global.svc.cluster.local/myapp/.*'
- matchers:
- uri:
prefix: /myapp
ignoreCase: true
forwardTo:
destinations:
- ref:
name: myapp
namespace: global
cluster: ${REMOTE_CLUSTER1}
port:
number: 8090
kind: SERVICE
Regex matching
Route requests to any paths that match an ECMAScript-style regular expression.
In a RouteTable resource, add the following matchers
section to your route:
...
http:
- headers:
- uri:
regex: <path>
...
In this example, regex: \/v.*\/myapp
indicates that any requests that contain the /v*/myapp
path, such as requests to myapp.global.svc.cluster.local/v1/myapp
and myapp.global.svc.cluster.local/v2/myapp
, are forwarded to the myapp
service.
apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
name: prefix-match
namespace: global
spec:
hosts:
- 'one.solo.io'
virtualGateways:
- name: istio-ingressgateway
namespace: gloo-mesh
cluster: ${REMOTE_CLUSTER1}
http:
# Match any requests that contain the '/v*/myapp' path
- matchers:
- uri:
regex: \/v.*\/myapp
forwardTo:
destinations:
- ref:
name: myapp
namespace: global
cluster: ${REMOTE_CLUSTER1}
port:
number: 8090
kind: SERVICE
Next steps
Now that you determined the type of request matching you want to use for your services, check out the guides in Forward requests to a destination to further build your route tables based on the destination type, and apply the route tables to your ingress gateway.