Traefik. Redirections

question is posted here: docker - Traefik. Redirections - Stack Overflow

please, help

In general I would recommend to post all content here and also start with the question, not let people read 3 pages of config first before even knowing the question and what to look for.

Update Traefik to use a recent version, v2.3 is from 2020. When going to v3, Host() will only accept a single domain.

This is how simple Traefik example redirects:

  whoami:
    image: traefik/whoami:v1.10
    networks:
      - proxy
    labels:
      - traefik.enable=true
      - traefik.http.routers.mywhoami.rule=Host(`whoami.example.com`) || Host(`www.whoami.example.com`)
      - traefik.http.services.mywhoami.loadbalancer.server.port=80

      - traefik.http.middlewares.mywwwredirect.redirectregex.regex=^https://www\.(.*)
      - traefik.http.middlewares.mywwwredirect.redirectregex.replacement=https://$${1}
      - traefik.http.routers.mywhoami.middlewares=mywwwredirect