58 lines
2.2 KiB
Plaintext
58 lines
2.2 KiB
Plaintext
|
---
|
|||
|
layout: docs
|
|||
|
page_title: Reroute HTTP Requests
|
|||
|
description: >-
|
|||
|
Learn how to configure Consul API Gateway to reroute HTTP requests to a specific path.
|
|||
|
---
|
|||
|
|
|||
|
# Reroute HTTP Requests
|
|||
|
|
|||
|
This topic describes how to configure Consul API Gateway to reroute HTTP requests.
|
|||
|
|
|||
|
## Requirements
|
|||
|
|
|||
|
1. Verify that the [requirements](/docs/api-gateway/tech-specs) have been met.
|
|||
|
1. Verify that the Consul API Gateway CRDs and controller have been installed and applied. Refer to [Installation](/docs/api-gateway/install) for details.
|
|||
|
|
|||
|
## Configuration
|
|||
|
|
|||
|
Specify the following fields in your `Route` configuration. Refer to the [Route configuration reference](/docs/api-gateway/configuration/routes) for details about the parameters.
|
|||
|
|
|||
|
- [`rules.filters.type`](/docs/api-gateway/configuration/routes#rules-filters-type): Set this parameter to `URLRewrite` to instruct Consul API Gateway to rewrite the URL when specific conditions are met.
|
|||
|
- [`rules.filters.urlRewrite`](/docs/api-gateway/configuration/routes#rules-filters-urlrewrite): Specify the `path` configuration.
|
|||
|
- [`rules.filters.urlRewrite.path`](/docs/api-gateway/configuration/routes#rules-filters-urlrewrite-path): Contains the paths that incoming requests should be rewritten to based on the match conditions.
|
|||
|
|
|||
|
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`.
|
|||
|
|
|||
|
<CodeBlockConfig filename="route.yaml">
|
|||
|
|
|||
|
```yaml hideClipboard
|
|||
|
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/
|
|||
|
```
|
|||
|
</CodeBlockConfig>
|