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.
RedirectScheme Middleware
Redirecting the Client to a Different Scheme/Port
The RedirectScheme middleware redirects requests when the request scheme is different from the configured scheme.
When Behind Another Reverse-Proxy When there is at least one other reverse-proxy between the client and Traefik, the other reverse-proxy (the last hop) needs to be a trusted one. Otherwise, Traefik would clean up the X-Forwarded headers, and the RedirectScheme middleware would not function as intended.
Configuration Examples
Redirect to HTTPS
Docker & Swarm
Kubernetes
File (YAML)
File (TOML)
labels :
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
Redirect to HTTPS with Custom Port
Docker & Swarm
Kubernetes
File (YAML)
File (TOML)
labels :
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.port=443"
- "traefik.http.middlewares.test-redirectscheme.redirectscheme.permanent=true"
Configuration Options
The scheme of the new URL (e.g., https, http).
The port of the new URL. Port in this configuration is a string, not a numeric value.
Apply a permanent redirection (HTTP 301 instead of HTTP 302).
Usage Examples
Force HTTPS
This is the most common use case - forcing all HTTP traffic to HTTPS:
http :
routers :
web-router :
rule : "Host(`example.com`)"
entryPoints :
- web
middlewares :
- redirect-to-https
service : my-service
web-secure-router :
rule : "Host(`example.com`)"
entryPoints :
- websecure
service : my-service
tls : {}
middlewares :
redirect-to-https :
redirectScheme :
scheme : https
permanent : true
Redirect with Port Change
http :
middlewares :
redirect-https-8443 :
redirectScheme :
scheme : https
port : "8443"
permanent : true