From 399fc729ac69cd230a174754c4544cfc893d55c8 Mon Sep 17 00:00:00 2001 From: Vincent BRIDIER Date: Mon, 3 Apr 2023 14:50:08 +0000 Subject: [PATCH] add www redirect middlewares --- common-services/traefik/middlewares.yaml | 34 +++++++++++++++++++++++- 1 file changed, 33 insertions(+), 1 deletion(-) diff --git a/common-services/traefik/middlewares.yaml b/common-services/traefik/middlewares.yaml index e60da78..f422754 100644 --- a/common-services/traefik/middlewares.yaml +++ b/common-services/traefik/middlewares.yaml @@ -6,4 +6,36 @@ metadata: spec: ipWhiteList: sourceRange: - - 0.0.0.0/0 \ No newline at end of file + - 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} \ No newline at end of file