StripPrefixRegex
Remove the matching prefixes from the URL path.
Docker
Kubernetes
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
name: test-stripprefixregex
spec:
stripPrefixRegex:
regex:
- "/foo/[a-z0-9]+/[0-9]+/"
Consul Catalog
Marathon
}
File (TOML)
[http.middlewares]
[http.middlewares.test-stripprefixregex.stripPrefixRegex]
regex = ["/foo/[a-z0-9]+/[0-9]+/"]
File (YAML)
Configuration Options
The StripPrefixRegex middleware will:
- strip the matching path prefix.
- store the matching path prefix in a
X-Forwarded-Prefix
header.
Tip
Use a stripPrefixRegex
middleware if your backend listens on the root path (/
) but should be routeable on a specific prefix.
Tip
Regular expressions can be tested using online tools such as Go Playground or the .
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 /
.
If your backend is serving assets (e.g., images or Javascript files), chances are it must return properly constructed relative URLs.
The header can be queried to build such URLs dynamically.