Birkhoff's Blog

Thoughts and technonogies.

Redirect domains to specific URLs with Traefik

Birkhoff Lee's Avatar October 21st 2018

I recently again needed to redirect a specific domain to a URL. For example redirecting to

I used to run some Docker containers which runs some web servers that redirect HTTP requests to make this work. I knew from the beginning that it wasn’t the most elegant or efficient way to do so, but I didn’t have any other idea for that. A friend once told me Firebase will do the job, but it’s limited to redirecting to a domain, not a URL, so no.

So today I was about to do the same thing (you can see me forked MorbZ/docker-web-redirect to BirkhoffLee/docker-web-redirect today), changed a bit in the repo and when I launched it up. All of a sudden when I was dealing with Traefik stuff I thought Traefik could’ve been doing the job for me, if I configured it correctly.

After searching around for a bit, some related GitHub issues came up, without the exact solutions. My workaround has some benefits:

  • does not need any other program to handle requests, therefore it’s efficient
  • built-in regex redirection support
  • centralized, easier to manage

This is the configuration block that you would want to put in your traefik.toml:





backend = "fake"
rule = ""
regex = "^https?://*)"
replacement = ""
permanent = true

backend = "fake"
rule = ""
regex = "^https?://*)"
replacement = "$1"
permanent = false

# so forth..

I hope I can get a centralized, web-based management panel that runs on a Docker container so I can manage these stuff more efficiently. If you have any other solutions to this topic, please comment down below to let me know!