2022-04-15 13:44:08 +00:00
|
|
|
---
|
|
|
|
title: "Traefik ReplacePath Documentation"
|
|
|
|
description: "In Traefik Proxy's HTTP middleware, ReplacePath updates paths before forwarding requests. Read the technical documentation."
|
|
|
|
---
|
|
|
|
|
2019-04-08 15:14:08 +00:00
|
|
|
# ReplacePath
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
Updating the Path Before Forwarding the Request
|
|
|
|
{: .subtitle }
|
|
|
|
|
2019-09-10 12:40:05 +00:00
|
|
|
<!--
|
|
|
|
TODO: add schema
|
|
|
|
-->
|
2019-02-26 13:50:07 +00:00
|
|
|
|
2021-02-11 13:34:04 +00:00
|
|
|
Replace the path of the request URL.
|
2019-02-26 13:50:07 +00:00
|
|
|
|
|
|
|
## Configuration Examples
|
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
```yaml tab="Docker"
|
2021-02-11 13:34:04 +00:00
|
|
|
# Replace the path with /foo
|
2019-04-03 12:32:04 +00:00
|
|
|
labels:
|
2019-09-23 15:00:06 +00:00
|
|
|
- "traefik.http.middlewares.test-replacepath.replacepath.path=/foo"
|
2019-04-03 12:32:04 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
```yaml tab="Kubernetes"
|
2021-02-11 13:34:04 +00:00
|
|
|
# Replace the path with /foo
|
2019-04-03 12:32:04 +00:00
|
|
|
apiVersion: traefik.containo.us/v1alpha1
|
|
|
|
kind: Middleware
|
|
|
|
metadata:
|
|
|
|
name: test-replacepath
|
|
|
|
spec:
|
|
|
|
replacePath:
|
|
|
|
path: /foo
|
|
|
|
```
|
|
|
|
|
2019-10-15 15:34:08 +00:00
|
|
|
```yaml tab="Consul Catalog"
|
2021-02-11 13:34:04 +00:00
|
|
|
# Replace the path with /foo
|
2019-10-15 15:34:08 +00:00
|
|
|
- "traefik.http.middlewares.test-replacepath.replacepath.path=/foo"
|
|
|
|
```
|
|
|
|
|
2019-07-22 07:58:04 +00:00
|
|
|
```yaml tab="File (YAML)"
|
2021-02-11 13:34:04 +00:00
|
|
|
# Replace the path with /foo
|
2019-07-22 07:58:04 +00:00
|
|
|
http:
|
|
|
|
middlewares:
|
|
|
|
test-replacepath:
|
|
|
|
replacePath:
|
|
|
|
path: "/foo"
|
|
|
|
```
|
|
|
|
|
2021-06-18 22:08:08 +00:00
|
|
|
```toml tab="File (TOML)"
|
|
|
|
# Replace the path with /foo
|
|
|
|
[http.middlewares]
|
|
|
|
[http.middlewares.test-replacepath.replacePath]
|
|
|
|
path = "/foo"
|
|
|
|
```
|
|
|
|
|
2019-02-26 13:50:07 +00:00
|
|
|
## Configuration Options
|
|
|
|
|
|
|
|
### General
|
|
|
|
|
|
|
|
The ReplacePath middleware will:
|
|
|
|
|
2021-02-11 13:34:04 +00:00
|
|
|
- replace the actual path with the specified one.
|
2019-04-08 15:14:08 +00:00
|
|
|
- store the original path in a `X-Replaced-Path` header.
|
2019-02-26 13:50:07 +00:00
|
|
|
|
2019-04-03 12:32:04 +00:00
|
|
|
### `path`
|
2019-02-26 13:50:07 +00:00
|
|
|
|
2021-02-11 13:34:04 +00:00
|
|
|
The `path` option defines the path to use as replacement in the request URL.
|