URI path matching

Match the targeted path of an incoming request against specific path criteria. 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 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 the ingress gateway forwards only requests that are exactly to one.solo.io/myapp. These requests are forwarded to the myapp service. Because the ignoreCase: true line is commented out, requests to paths such as one.solo.io/MYapp or one.solo.io/myApp are not forwarded.

apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: exact-match
  namespace: global
spec:
  hosts:
    - 'one.solo.io'
  virtualGateways:
    - name: ingress-gateway
      namespace: gloo-mesh
      cluster: ${REMOTE_CLUSTER1}
  http:
  # Match only requests to exactly 'one.solo.io/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 the ingress gateway forwards any requests that contain the /myapp path prefix, such as requests to one.solo.io/myapp/foo and one.solo.io/myapp/bar, to the myapp service. Because the example includes ignoreCase: true, requests to paths such as one.solo.io/MYapp/foo or one.solo.io/myApp/bar are also forwarded.

apiVersion: networking.gloo.solo.io/v2
kind: RouteTable
metadata:
  name: prefix-match
  namespace: global
spec:
  hosts:
    - 'one.solo.io'
  virtualGateways:
    - name: ingress-gateway
      namespace: gloo-mesh
      cluster: ${REMOTE_CLUSTER1}
  http:
  # Match any requests to 'one.solo.io/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 the ingress gateway forwards any requests that contain the /v*/myapp path, such as requests to one.solo.io/v1/myapp and one.solo.io/v2/myapp, 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: ingress-gateway
      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.