Documentation Index
Fetch the complete documentation index at: https://mintlify.com/traefik/traefik/llms.txt
Use this file to discover all available pages before exploring further.
StripPrefix Middleware
Removing Prefixes From the Path Before Forwarding The StripPrefix middleware removes specified prefixes from the URL path before forwarding the request to the service.Configuration Examples
Configuration Options
List of prefixes to strip from the request URL.For instance,
/products also matches /products/shoes and /products/shirts.The middleware stores the stripped prefix in the X-Forwarded-Prefix header.Ensures the resulting stripped path is not an empty string by replacing it with
/ when necessary.How It Works
The StripPrefix middleware:- Strips the matching path prefix from the request URL
- Stores the stripped prefix in the
X-Forwarded-Prefixheader - Forwards the modified request to the backend service
Backend Asset URLsIf your backend is serving assets (e.g., images or JavaScript files), it can use the
X-Forwarded-Prefix header to properly construct relative URLs.For example, if the original request is /products/shoes/image.png and you strip /products, the backend should return URLs like /products/shoes/image.png (not /image.png).Usage Examples
Exposing Backend on a Subpath
Use StripPrefix when your backend listens on the root path (/) but should be exposed on a specific prefix:
- Request:
https://example.com/api/users - Forwarded to backend:
http://backend:8080/users X-Forwarded-Prefix: /api