Traefik redirect

labels:
      - "traefik.enable=true"
      - "traefik.docker.network=mynetwork"
      - "traefik.http.routers.rechajwebapp.entrypoints=web"      
      - "traefik.http.routers.rechajwebapp.rule=Host(`www.mydomain.xyz`)"

How can i get redirect to work. I want to the following
if I type mydomain.xyz. I get a 404

If I type www.mydomain.xyz it works. how can i redirect to www

Hello,

  whoami:
    image: containous/whoami
    labels:
      traefik.enable: true

      traefik.http.routers.whoami.rule: Host(`whoami.localhost`, `www.whoami.localhost`)
      traefik.http.routers.whoami.entrypoints: web
      traefik.http.routers.whoami.middlewares: trim_www

      # middleware: http://www. to  http://
      traefik.http.middlewares.trim_www.redirectregex.regex: ^http://www\.(.+)
      traefik.http.middlewares.trim_www.redirectregex.replacement: http://$${1}
      traefik.http.middlewares.trim_www.redirectregex.permanent: true

For a more global approach:

Hello

thanks for the feedback I want the other way around.

Can you provide the example..

or any reason why www should be trimmed?

I want to go to www

mydomain.xyz I want to be redirect to www.mydomain.xyz

sorry I provided the inverse, but it's the same approach:

  whoami:
    image: containous/whoami
    labels:
      traefik.enable: true

      traefik.http.routers.whoami.rule: Host(`whoami.localhost`, `www.whoami.localhost`)
      traefik.http.routers.whoami.entrypoints: web
      traefik.http.routers.whoami.middlewares: add_www

      # middleware: http:// to  http://www.
      traefik.http.middlewares.add_www.redirectregex.regex: ^http://whoami\.localhost(.+)
      traefik.http.middlewares.add_www.redirectregex.replacement: http://www.whoami.localhost$${1}
      traefik.http.middlewares.add_www.redirectregex.permanent: true

or

  whoami:
    image: containous/whoami
    labels:
      traefik.enable: true

      traefik.http.routers.whoami.rule: Host(`www.whoami.localhost`)
      traefik.http.routers.whoami.entrypoints: web

      traefik.http.routers.whoami_redirect.rule: Host(`whoami.localhost`)
      traefik.http.routers.whoami_redirect.entrypoints: web
      traefik.http.routers.whoami_redirect.middlewares: add_www

      # middleware: http:// to  http://www.
      traefik.http.middlewares.add_www.redirectregex.regex: ^http://(.+)
      traefik.http.middlewares.add_www.redirectregex.replacement: http://www.$${1}
      traefik.http.middlewares.add_www.redirectregex.permanent: true