Redirect the requests
The example below shows how to redirect the HTTP requests on the port 80 to the port 443, changing the scheme into HTTPS. You can apply the redirection either at the EntryPoint level to redirect every request or on a router, using a middleware.
Redirect from Entrypoints
Redirect every request from the entrypoint web
to websecure
.
- Static Configuration
- Helm Chart Values
## Static configuration
entryPoints:
web:
address: :80
http:
redirections:
entryPoint:
to: websecure
scheme: https
websecure:
address: :443
tls: {}
## Values file
ports:
web:
port: 80
# The option add the scheme https automaticaly
redirectTo: websecure
websecure:
port: 443
Redirect from Routers
Redirect every request from the entrypoint web
to the port 443
for the dedicated IngressRoute
.
In such a case, every request that matches the rule is redirected between the entrypoints.
- Middleware RedirectScheme
- IngressRoute
- Service & Deployment
apiVersion: traefik.io/v1alpha1
kind: Middleware
metadata:
name: test-redirectscheme
spec:
redirectScheme:
scheme: https
port: "443"
apiVersion: traefik.io/v1alpha1
kind: IngressRoute
metadata:
name: applications-apigateway-headers
namespace: apps
spec:
entryPoints:
- web
routes:
- match: Host(`myexample.net`)
kind: Rule
services:
- name: whoami
port: 80
middlewares:
- name: test-redirectscheme
kind: Deployment
apiVersion: apps/v1
metadata:
name: whoami
namespace: apps
spec:
replicas: 1
selector:
matchLabels:
app: whoami
template:
metadata:
labels:
app: whoami
spec:
containers:
- name: whoami
image: traefik/whoami
---
apiVersion: v1
kind: Service
metadata:
name: whoami
namespace: apps
labels:
app: whoami
spec:
type: ClusterIP
ports:
- port: 80
name: whoami
selector:
app: whoami
Related Content
- Know more about the Entrypoint redirection in the dedicated section.
- See the RedirectScheme middleware options in the dedicated section.
- See how to modify the requests and the responses in the dedicated section.