Redirectregex to `www` doesn't work with AWS ECS

Hi, I have tried several patterns

        "traefik.enable"                                                              = "true",
        "traefik.http.routers.example.rule"                               = "Host(`example.com`, `www.example.com`)",
        "traefik.http.routers.example.entrypoints"                        = "websecure",
        "traefik.http.routers.example.service"                            = "example",
        "traefik.http.middlewares.redirect-to-www.redirectregex.regex"                = "^https://(example.com)(.*)"
        "traefik.http.middlewares.redirect-to-www.redirectregex.replacement"          = "https://www.$${1}$${2}"
        "traefik.http.middlewares.redirect-to-www.redirectregex.permanent"            = "true"
        "traefik.http.routers.example.middlewares"                        =  "redirect-to-www"

Or

        "traefik.http.middlewares.redirect-to-www.redirectregex.replacement"          = "https://www.${1}${2}"

but non of them work. Is this a bug related to ECS provider?

I tested with curl:

*   Trying 12.13.123.12...
* TCP_NODELAY set
* Connected to <example.com> (12.13.123.12) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /etc/ssl/cert.pem
  CApath: none
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* TLSv1.2 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: CN=<example.com>
*  start date: Sep 15 00:00:00 2021 GMT
*  expire date: Oct 14 23:59:59 2022 GMT
*  subjectAltName: host "<example.com>" matched cert's "<example.com>"
*  issuer: C=US; O=Amazon; OU=Server CA 1B; CN=Amazon
*  SSL certificate verify ok.
> GET / HTTP/1.1
> Host: <example.com>
> User-Agent: curl/7.64.1
> Accept: */*
>
< HTTP/1.1 200 OK
< Accept-Ranges: bytes
< Cache-Control: max-age=300
< Content-Length: 5138
< Content-Type: text/html
< Date: Tue, 12 Oct 2021 04:20:56 GMT
< Etag: "61650803-1412"
< Last-Modified: Tue, 12 Oct 2021 03:58:59 GMT
< Server: nginx
  • Actual domain and IPs was replaced with <example.com> and fake IPs

This is what I have on traefik dashboard. the Middleware is applied. I tried both with 1 $ and double $$. but non of them work.

finally I made it work. it was because of the https, actually it should have been http.

1 Like