Traefik full domain redirect TOML config example

Based on our basic Traefik config Simple Traefik docker-compose setup with Lets Encrypt Cloudflare DNS-01 & TLS-ALPN-01 & HTTP-01 challenges, this is a complete TOML config to redirect my.olddomain.com to my.newdomain.com, with my.olddomain.com being served using a Let’s Encrypt certificate with wildcard (*.olddomain.com) and the DNS-01 challenge.

myredirect.toml
[http.routers]
  [http.routers.RedictMyOlddomain]
    rule = "Host(`my.olddomain.com`)"
    entryPoints = ["websecure"]
    middlewares = ["RedictMyOlddomain"]
    service = "noop"
    [http.routers.RedictMyOlddomain.tls]
      certResolver = "cloudflare-ec384"
      [[http.routers.RedictMyOlddomain.tls.domains]]
        main = "olddomain.com"
        sans = ["*.olddomain.com"]

[http.middlewares]
  [http.middlewares.RedictMyOlddomain.redirectRegex]
    regex = "https?://my\\.olddomain\\.com/(.*)"
    replacement = "https://my.newdomain.com/$1"
    permanent = true

[http.services]
  [http.services.noop.loadBalancer]
    [[http.services.noop.loadBalancer.servers]]
      url = "http://127.0.0.1"  # dummy target to make Traefik happy

Check out similar posts by category: Traefik