Back to Traefik

Traefik StripPrefix Documentation

docs/content/reference/routing-configuration/http/middlewares/stripprefix.md

3.7.0-ea.31.7 KB
Original Source

The stripPrefix middleware strips the matching path prefix and stores it in an X-Forwarded-Prefix header.

!!! tip

Use a `StripPrefix` middleware if your backend listens on the root path (`/`) but should be exposed on a specific prefix.

Configuration Examples

yaml
# Strip prefix /foobar and /fiibar
http:
  middlewares:
    test-stripprefix:
      stripPrefix:
        prefixes:
          - "/foobar"
          - "/fiibar"
toml
# Strip prefix /foobar and /fiibar
[http.middlewares]
  [http.middlewares.test-stripprefix.stripPrefix]
    prefixes = ["/foobar", "/fiibar"]
yaml
# Strip prefix /foobar and /fiibar
labels:
  - "traefik.http.middlewares.test-stripprefix.stripprefix.prefixes=/foobar,/fiibar"
json
// Strip prefix /foobar and /fiibar
{
  "Tags" : [
    "traefik.http.middlewares.test-stripprefix.stripprefix.prefixes=/foobar,/fiibar"
  ]
}
yaml
# Strip prefix /foobar and /fiibar
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
  name: test-stripprefix
spec:
  stripPrefix:
    prefixes:
      - /foobar
      - /fiibar

Configuration Options

FieldDescriptionDefaultRequired
<a id="opt-prefixes" href="#opt-prefixes" title="#opt-prefixes">prefixes</a>List of prefixes to strip from the request URL.
If your backend is serving assets (for example, images or JavaScript files), it can use the X-Forwarded-Prefix header to construct relative URLs.[]No

{% include-markdown "includes/traefik-for-business-applications.md" %}