@@ -84,6 +84,12 @@ services:
8484 - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls=true
8585 - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.tls.certresolver=le
8686
87+ # Define Traefik Middleware to handle domain with and without "www" to redirect to only one
88+ - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^http(s)?://www.(${DOMAIN?Variable not set})/(.*)
89+ # Redirect a domain with www to non-www
90+ - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=http$${1}://${DOMAIN?Variable not set}/$${3}
91+
92+ # Enable www redirection for HTTP and HTTPS
8793 - traefik.http.routers.${STACK_NAME?Variable not set}-backend-http.middlewares=https-redirect,${STACK_NAME?Variable not set}-www-redirect
8894 - traefik.http.routers.${STACK_NAME?Variable not set}-backend-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
8995
@@ -113,16 +119,8 @@ services:
113119 - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls=true
114120 - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.tls.certresolver=le
115121
116- # Handle domain with and without "www" to redirect to only one
117- # To disable www redirection remove the next line
118- - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.regex=^http(s)?://www.(${DOMAIN?Variable not set})/(.*)
119- # Redirect a domain with www to non-www
120- # To disable it remove the next line
121- - traefik.http.middlewares.${STACK_NAME?Variable not set}-www-redirect.redirectregex.replacement=http$${1}://${DOMAIN?Variable not set}/$${3}
122- # Middleware to redirect www, to disable it remove the next line
122+ # Enable www redirection for HTTP and HTTPS
123123 - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-https.middlewares=${STACK_NAME?Variable not set}-www-redirect
124- # Middleware to redirect www, and redirect HTTP to HTTPS
125- # to disable www redirection remove the section: ${STACK_NAME?Variable not set}-www-redirect,
126124 - traefik.http.routers.${STACK_NAME?Variable not set}-frontend-http.middlewares=https-redirect,${STACK_NAME?Variable not set}-www-redirect
127125volumes :
128126 app-db-data :
0 commit comments