Redirect ->

Hi all,
I recently switched to Traefik using Docker and It's been a breeze.

The only thing I have yet to figure out is how I would go about directing my main domain name to a subdomain.
I tried setting an HTTP redirect middleware without success (this is from the docker-compose.yml of the Traefik container:

      - "traefik.enable=true"
      - "traefik.http.routers.domain.entrypoints=websecure"
      - "traefik.http.routers.domain.rule=Host(``)"
      - "traefik.http.routers.domain.service=noop@internal"
      - "traefik.http.routers.domain.middlewares=subdomain-redirect"
      - 'traefik.http.middlewares.subdomain-redirect.redirectregex.regex=^*)'
      - 'traefik.http.middlewares.subdomain-redirect.redirectregex.replacement=$${1}'
      - "traefik.http.middlewares.subdomain-redirect.redirectregex.permanent=true"

I realise there are plently of similar questions around the web, but I could not figure it out...
I've tried several variations of the code above without success.

How should I go about redirecting my main domain to a subdomain?
Any pointers would be greatly appreciated.

Thank you!


I managed to solve this like so:

      - "traefik.enable=true"
      - "traefik.http.routers.domain.entrypoints=websecure"
      - "traefik.http.routers.domain.rule=Host(``)"
      - "traefik.http.routers.domain.tls.certresolver=certresolver"
      - "traefik.http.routers.domain.middlewares=domain"
      - 'traefik.http.middlewares.domain.redirectregex.regex=^*)'
      - 'traefik.http.middlewares.domain.redirectregex.replacement=$${1}'
      - "traefik.http.middlewares.domain.redirectregex.permanent=true"`

Hope this helps!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.