This is tested with Traefik 1.7
This is how to redirect the root or base path to a sub path in Traefik using Docker labels:
Goals
https://example.com
->https://example.com/abc/xyz/
https://example.com/
->https://example.com/abc/xyz/
https://example.com/something
-> no redirect
We will match <begin of line>https://<any chars but not slash AS group1><slash or nothing><end of line>
and replace it with https://<group1>/abc/xyz/
.
In regex we have to escape a /
character by \/
. In docker-compose labels we need to escape again, so that it becomes \\\\/
.
We also need to escape $
to $$
because of docker-compose.
labels:
- "traefik.frontend.rule=Host:example.com"
- "traefik.frontend.redirect.regex=^https:\\\\/\\\\/([^\\\\/]+)\\\\/?$$"
- "traefik.frontend.redirect.replacement=https://$$1/abc/xyz/"
- "traefik.port=80"
- "traefik.enable=true"
Thanks, everyone for your contributions. I just started trying Traefik today and unfortunately, the above solutions do not work for me. Here is my setup:
two very simple static webapps, each app running in a separate container
Here are the contents of the html files:
I am trying to access app1 and app2 via something like
With the setup below, I can access the main page of each app but not the subfolders.
The routing seems to work, e.g. I can see in the browser address bar:
But the page is not displayed (seems the path is not correct) and I get the 404 page not found error.
My network setup as follows:
What I am missing?