Reroute HTTP Requests

This topic describes how to configure Consul API Gateway to reroute HTTP requests.

Requirements

  1. Verify that the requirements have been met.
  2. Verify that the Consul API Gateway CRDs and controller have been installed and applied. Refer to Installation for details.

Configuration

Specify the following fields in your Route configuration. Refer to the Route configuration reference for details about the parameters.

To configure the route to accept paths with or 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/. As a result, requests to /incoming-request-prefix/request-path are received by backendRef as /prefix-backend-receives/request-path.

Reroute HTTP Requests - 图1

route.yaml

  1. apiVersion: gateway.networking.k8s.io/v1beta1
  2. kind: HTTPRoute
  3. metadata:
  4. name: example-route
  5. ##...
  6. spec:
  7. parentRefs:
  8. - group: gateway.networking.k8s.io
  9. kind: Gateway
  10. name: api-gateway
  11. rules:
  12. - backendRefs:
  13. . . .
  14. filters:
  15. - type: URLRewrite
  16. urlRewrite:
  17. path:
  18. replacePrefixMatch: /prefix-backend-receives/
  19. type: ReplacePrefixMatch
  20. matches:
  21. - path:
  22. type: PathPrefix
  23. value: /incoming–request-prefix/