Hi!
There seems to be an issue getting redirectRegex
middleware to work with FQDNs. Here's an example:
fqdnDomainRedirect:
redirectRegex:
regex: "^https?://(.*\\.example\\.com)\\.(.*)"
replacement: "https://${1}${2}"
permanent: true
This is supposed to redirect URLs like https://foo.example.com./path to https://foo.example.com/path, but it doesn't work.
Could it be that Traefik is ignoring the trailing dot as part of DNS normalization rules and doesn't proceed to passing it to the middleware?
Middleware status in Traefik dashboard is successful, the regex works fine in regex101.com.
Thanks!
Have you tried to modify your config a bit, remove the dot, to see if it works without?
1 Like
Are you sure that requests to foo.example.com.
are able to reach your Traefik? I doubt that a DNS request of an hostname ending with a dot would properly resolve.
1 Like
@wollomatic
responding on behalf of @Funghorn.
Currently foo.example.com./blahblah
request works and a service is available, but Redirect to foo.example.com/blahblah doesn't work in Traefik.
in Network console I see
Request URL:
foo.example.com./blahblah
Request Method:
GET
Status Code:
200 OK
Redirect foo.example.com. to foo.example.com works.
responding on behalf of @Funghorn.
Tried regex: "^https?://(.*\\.example\\.com)(.*)"
and got an error: "Load cannot follow more than 20 redirections"
You get the error in the browser? Both regex and replacement would be worth to share.
1 Like
Yes, I get the error in the browser: "Load cannot follow more than 20 redirections"
sure, it was:
fqdnDomainRedirect:
redirectRegex:
regex: "^https?://(.*\\.example\\.com)(.*)"
replacement: "https://${1}${2}"
permanent: true```
You are taking the request URL, split it in two, then redirect to the same combined result. So it's just going in circles. Browser will error after some rounds.
1 Like
Thank you for your answer.
fqdnDomainRedirect:
redirectRegex:
regex: "^https?://(.*\\.example\\.com)\\.(.*)"
replacement: "https://${1}${2}"
permanent: true
https://example.com. -> https://example.com
works good.
but the issue still exists with redirect:
https://example.com./abc -> https://example.com/abc
https://example.com./abc
is available but without redirect to https://example.com/abc
Make sure to not have a global http-to-https redirect on entrypoint
set. I bet that is your issue. It will take over before any middlewares.
This works for me, not sure if the additional ?
is relevant:
http:
middlewares:
fqdnDomainRedirect:
redirectRegex:
regex: "^https?://(.*?\\.example\\.com)\\.(.*)"
replacement: "https://${1}${2}"
curl -v --header "Host: demo.example.com." http://1.2.3.4/path
->
Location: https://demo.example.com/path