Skip to content

Instantly share code, notes, and snippets.

@coltondick
Last active August 13, 2025 18:20
Show Gist options
  • Select an option

  • Save coltondick/125bc7083d19f259529802490f97b94c to your computer and use it in GitHub Desktop.

Select an option

Save coltondick/125bc7083d19f259529802490f97b94c to your computer and use it in GitHub Desktop.
Traefik Redirect Configuration (Sanitized Example)

Traefik Redirect Configuration (Sanitized Example)

Edit your dynamic_config.yml in the config/traefik directory of your Pangolin stack.


1. Middlewares

middlewares:
  redirect-subdomains-to-domain2:
    redirectRegex:
      # foo.old-example.com/bar -> https://foo.new-example.com/bar
      regex: ^https?://([^.]+(?:\.[^.]+)*)\.old-example\.com(.*)
      replacement: https://$1.new-example.com$2
      permanent: true

  redirect-apex-to-domain2:
    redirectRegex:
      regex: ^https?://old-example\.com(.*)
      replacement: https://new-example.com$1
      permanent: true
  • Replace old-example.com with your source domain (e.g., foo.com)
  • Replace new-example.com with your destination domain (e.g., example.com)

2. Routers

routers:
  # Subdomains (HTTP)
  r-sub-http:
    rule: "HostRegexp(`.+\\.old-example\\.com`)"
    entryPoints: ["web"]
    middlewares: ["redirect-subdomains-to-domain2"]
    service: "noop@internal"
    priority: 3000

  # Subdomains (HTTPS)
  r-sub-https:
    rule: "HostRegexp(`.+\\.old-example\\.com`)"
    entryPoints: ["websecure"]
    tls: {}
    middlewares: ["redirect-subdomains-to-domain2"]
    service: "noop@internal"
    priority: 3000

  # Apex (HTTP)
  r-apex-http:
    rule: "Host(`old-example.com`)"
    entryPoints: ["web"]
    middlewares: ["redirect-apex-to-domain2"]
    service: "noop@internal"
    priority: 3000

  # Apex (HTTPS)
  r-apex-https:
    rule: "Host(`old-example.com`)"
    entryPoints: ["websecure"]
    tls: {}
    middlewares: ["redirect-apex-to-domain2"]
    service: "noop@internal"
    priority: 3000

3. Services

services:
  noop:
    loadBalancer:
      servers:
        - url: http://127.0.0.1

4. Restart Traefik

docker restart traefik

5. Test the Redirect

curl -Ik https://localhost:443 -H 'Host: api.old-example.com'

Expected Output:

HTTP/2 308
location: https://api.new-example.com/
content-length: 18
date: Wed, 13 Aug 2025 18:15:40 GMT
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment