add www redirect middlewares

This commit is contained in:
Vincent BRIDIER 2023-04-03 14:50:08 +00:00
parent ede328ec8e
commit 399fc729ac

View file

@ -6,4 +6,36 @@ metadata:
spec:
ipWhiteList:
sourceRange:
- 0.0.0.0/0
- 0.0.0.0/0
---
# Redirect no-www URLs to their www equivalent
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: redirect-no-www-to-www
spec:
# Redirect a request from an url to another with regex matching and replacement
redirectRegex:
# Apply a permanent redirection (HTTP 301)
permanent: true
# The regular expression to match and capture elements from the request URL
regex: ^https?://(?:www\\.)?(.+)
# How to modify the URL to have the new target URL
replacement: https://www.${1}
---
# Redirect www URLs to their no-www equivalent
apiVersion: traefik.containo.us/v1alpha1
kind: Middleware
metadata:
name: redirect-www-to-no-www
spec:
# Redirect a request from an url to another with regex matching and replacement
redirectRegex:
# Apply a permanent redirection (HTTP 301)
permanent: true
# The regular expression to match and capture elements from the request URL
regex: ^https?://www\\.(.+)
# How to modify the URL to have the new target URL
replacement: https://${1}