I have a docker that is behind the Traefik proxy. I try to redirect all traffic (except the cdn) to https://www.mysite.nl
. I configured a regex as you can see below. But unfortunatly it does not work. I receive 404 on all hosts. What am i missing?
Here you can test the regex: https://regex101.com/r/mwt573/2
- traefik.frontend.priority=5
- traefik.frontend.rule=Host:mysite.nl, www.mysite.nl, mysite.com, www.mysite.com, cdn.mysite.net
- traefik.frontend.redirect.regex=^https?://(?:www.)?mysite\.(?:nl|com)(.*)
- traefik.frontend.redirect.replacement=https://www.mysite.nl$${1}
This setup worked for me, but did not redirect the .com domain to .nl. It also places a /
after each url.
- traefik.frontend.priority=5
- traefik.frontend.rule=Host:mysite.nl, www.mysite.nl, cdn.mysite.net, mysite.com, www.mysite.com
- traefik.frontend.redirect.regex=^https?://mysite.nl/(.*)
- frontend.redirect.replacement=https://www.mysite.nl/$${1}
I am not sure why. But removing the non capturing group and unescaping the dot worked for me.
Working example:
- traefik.frontend.priority=5
- traefik.frontend.rule=Host:mysite.nl, www.mysite.nl, cdn.mysite.net, mysite.com, www.mysite.com
- traefik.frontend.redirect.regex=^https?://(www.)?mysite(.nl|.com)(.*)
- traefik.frontend.redirect.replacement=https://www.mysite.nl$${3}
I have been suffering with my docker run command (executable script file) and regex/replacement labels for a while. This is what I came to using it for www to non-www url rewrite:
docker inspect
command under the "Labels" property, if your regex was caught properly by the run script.My result for www to non-www is:
-l traefik.frontend.redirect.regex='^https?://(?:www[.])(.*)'
-l traefik.frontend.redirect.replacement='https://${1}'
Your claimed solution should work properly, I slightly rewrote it:
-l traefik.frontend.redirect.regex='^https?://(?:www[.])?mysite[.](?:nl|com)(.*)'
-l traefik.frontend.redirect.replacement='https://www.mysite.nl${1}'