First of all, I'm aware that Global redirect www to non-www with HTTPS redirection exists, but unfortunately I've tried everything here (and searched around the forum for more solutions), to no avail.
What I'm trying to do, is to set up a global www to non-www redirection.
To that end, I've set up a "global" middleware as follows.
Part of the traefik static config that's relevant:
entryPoints:
web:
address: :80
http:
redirections:
entryPoint:
to: web-secure
scheme: https
permanent: true
priority: 10
web-secure:
address: :443
http:
middlewares:
- no-www@file
The file-based dynamic config (and I can confirm that the dynamic config is being picked up properly):
http:
middlewares:
no-www:
redirectregex: # I've also tried redirectRegex, the docs are mixed on this!
regex: ^(?:https://)?(?:www\.)?(.+)
replacement: https://${1}
permanent: true
So the way it's supposed to work is that the regex captures the actual "body" of the URL (ignoring http/https, www or non-www) and redirect to the https, non-www version of it. And I even tried it on the go playground as the docs suggested, which works as expected: The Go Playground
However, when I visit both www.mysite.com
and https://www.mysite.com
, traefik returns 404, even though the mysite.com
and https://mysite.com
works fine.
Please, can somebody tell me what I'm missing?
I've tried different regexes such as ^https?://(?:www\.)?(.+)
, ^https?://(?:www\\.)?(.+)
, and even escaping the /