I sett up Traefik to manage my docker containers but I can redirect www to non-www for my domain. I've tried everything in the forums but no luck
labels:
- "traefik.enable=true"
- "traefik.http.routers.node.entrypoints=http"
- "traefik.http.routers.node.rule=Host(`awebsite.com`) || Host(`www.awebsite.com`)"
- "traefik.http.middlewares.vk-https-redirect.redirectscheme.scheme=https"
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^https://www.awebsite.com/(.*)"
- "traefik.http.middlewares.test-redirectregex.redirectregex.replacement=https://awebsite.com/$${1}"
- "traefik.http.routers.node.middlewares=vk-https-redirect"
- "traefik.http.routers.node-secure.entrypoints=https"
- "traefik.http.routers.node-secure.rule=Host(`awebsite.com`) || Host(`www.awebsite.com`)"
- "traefik.http.routers.node-secure.tls=true"
- "traefik.http.routers.node-secure.tls.certresolver=http"
- "traefik.http.routers.node-secure.service=node"
- "traefik.http.services.node.loadbalancer.server.port=8000"
- "traefik.docker.network=proxy"
It not enough to define the redirect middleware, you also need to use it with the defined routers
here is you middleware definitions
- "traefik.http.middlewares.test-redirectregex.redirectregex.regex=^https://www.awebsite.com/(.*)"
- "traefik.http.middlewares.test-redirectregex.redirectregex.replacement=https://awebsite.com/$${1}"
you may need to add this lable too
traefik.http.middlewares.test-redirectregex.redirectregex.permanent=true
but you never used it in any of the defined routers. For instance, if you want this to apply to node-secure
router, you need to add this label
- "traefik.http.routers.node-secure.middlewares=test-redirectregex"
More information, details, and examples can be found in this article
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With