I recently again needed to redirect a specific domain to a URL. For example redirecting google.birkhoff.me to https://www.google.com.

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 told me Firebase can do the job, but it's limited to redirecting to a domain, not a URL.

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, 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 = "Host:test.birkhoff.me"
        regex = "^https?://test.birkhoff.me/(.*)"
        replacement = "https://google.com"
        permanent = true

      backend = "fake"
        rule = "Host:another-test.birkhoff.me"
        regex = "^https?://another-test.birkhoff.me/(.*)"
        replacement = "https://twitter.com/$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!