2019-04-08 15:14:08 +00:00
# StripPrefix
2019-02-26 13:50:07 +00:00
Removing Prefixes From the Path Before Forwarding the Request
{: .subtitle }
2019-04-08 15:14:08 +00:00
`TODO: add schema`
Remove the specified prefixes from the URL path.
## Configuration Examples
```yaml tab="Docker"
2019-04-29 17:00:05 +00:00
# Strip prefix /foobar and /fiibar
2019-04-08 15:14:08 +00:00
labels:
2019-09-09 08:36:08 +00:00
- "traefik.http.middlewares.test-stripprefix.stripprefix.prefixes=/foobar,/fiibar"
2019-04-08 15:14:08 +00:00
```
```yaml tab="Kubernetes"
2019-04-29 17:00:05 +00:00
# Strip prefix /foobar and /fiibar
2019-04-08 15:14:08 +00:00
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: test-stripprefix
spec:
2019-06-18 07:50:05 +00:00
stripPrefix:
2019-06-11 18:42:04 +00:00
prefixes:
- /foobar
- /fiibar
2019-04-08 15:14:08 +00:00
```
2019-04-15 16:22:07 +00:00
```json tab="Marathon"
"labels": {
2019-09-09 08:36:08 +00:00
"traefik.http.middlewares.test-stripprefix.stripprefix.prefixes": "/foobar,/fiibar"
2019-04-15 16:22:07 +00:00
}
```
2019-04-08 15:14:08 +00:00
```yaml tab="Rancher"
2019-04-29 17:00:05 +00:00
# Strip prefix /foobar and /fiibar
2019-04-08 15:14:08 +00:00
labels:
2019-09-09 08:36:08 +00:00
- "traefik.http.middlewares.test-stripprefix.stripprefix.prefixes=/foobar,/fiibar"
2019-04-08 15:14:08 +00:00
```
2019-07-22 07:58:04 +00:00
```toml tab="File (TOML)"
2019-04-29 17:00:05 +00:00
# Strip prefix /foobar and /fiibar
2019-04-08 15:14:08 +00:00
[http.middlewares]
2019-07-01 09:30:05 +00:00
[http.middlewares.test-stripprefix.stripPrefix]
prefixes = ["/foobar", "/fiibar"]
2019-04-08 15:14:08 +00:00
```
2019-07-22 07:58:04 +00:00
```yaml tab="File (YAML)"
# Strip prefix /foobar and /fiibar
http:
middlewares:
test-stripprefix:
stripPrefix:
prefixes:
- "/foobar"
- "/fiibar"
```
2019-04-08 15:14:08 +00:00
## Configuration Options
### General
The StripPrefix middleware will:
- strip the matching path prefix.
- store the matching path prefix in a `X-Forwarded-Prefix` header.
!!! tip
Use a `StripPrefix` middleware if your backend listens on the root path (`/`) but should be routeable on a specific prefix.
### `prefixes`
The `prefixes` option defines the prefixes to strip from the request URL.
For instance, `/products` would match `/products` but also `/products/shoes` and `/products/shirts` .
Since the path is stripped prior to forwarding, your backend is expected to listen on `/` .
2019-02-26 13:50:07 +00:00
If your backend is serving assets (e.g., images or Javascript files), chances are it must return properly constructed relative URLs.
Continuing on the example, the backend should return `/products/shoes/image.png` (and not `/images.png` which Traefik would likely not be able to associate with the same backend).
2019-04-08 15:14:08 +00:00
The `X-Forwarded-Prefix` header can be queried to build such URLs dynamically.