Consul
Reroute HTTP Requests
This topic describes how to configure Consul API Gateway to reroute HTTP requests.
Requirements
- Verify that the requirements have been met.
- Verify that the Consul API Gateway CRDs and controller have been installed and applied. Refer to Installation for details.
Configuration
Configure the following fields in your Route configuration to use this feature. Refer to the Route configuration reference for details about the parameters.
rules.filters.type: Set this parameter toURLRewriteto instruct Consul API Gateway to rewrite the URL when specific conditions are met.rules.filters.urlRewrite: Specify thepathconfiguration.rules.filters.urlRewrite.path: Contains the paths that incoming requests should be rewritten to based on the match conditions.
Note that if the route is configured to accept paths with and without a trailing slash, you must make two separate routes to handle each case.
Example
In the following example, requests to /incoming-request-prefix/ are forwarded to the backendRef as /prefix-backend-receives/. A request to /incoming-request-prefix/request-path, for instance, is received by the backendRef as /prefix-backend-receives/request-path.
route.yaml
apiVersion: gateway.networking.k8s.io/v1beta1
kind: HTTPRoute
metadata:
name: example-route
##...
spec:
parentRefs:
- group: gateway.networking.k8s.io
kind: Gateway
name: api-gateway
rules:
- backendRefs:
. . .
filters:
- type: URLRewrite
urlRewrite:
path:
replacePrefixMatch: /prefix-backend-receives/
type: ReplacePrefixMatch
matches:
- path:
type: PathPrefix
value: /incoming–request-prefix/