Skip to content

Instantly share code, notes, and snippets.

@kekru
Last active November 22, 2024 05:09
Show Gist options
  • Select an option

  • Save kekru/d088be6a3fa844089ae62d80c077bb38 to your computer and use it in GitHub Desktop.

Select an option

Save kekru/d088be6a3fa844089ae62d80c077bb38 to your computer and use it in GitHub Desktop.

Revisions

  1. kekru revised this gist Sep 20, 2019. 1 changed file with 3 additions and 1 deletion.
    4 changes: 3 additions & 1 deletion traefik-redirect-path.md
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,8 @@
    # Traefik: redirect base or root path to a subpath

    This is how to redirect the root or base path to a sub path in Traefik using Docker labels:
    > 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/`
  2. kekru revised this gist May 30, 2019. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion traefik-redirect-path.md
    Original file line number Diff line number Diff line change
    @@ -1,4 +1,4 @@
    # Redirect base or root path to a subpath
    # Traefik: redirect base or root path to a subpath

    This is how to redirect the root or base path to a sub path in Traefik using Docker labels:
    Goals
  3. kekru created this gist May 30, 2019.
    22 changes: 22 additions & 0 deletions traefik-redirect-path.md
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    # Redirect base or root path to a subpath

    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.

    ```yaml
    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"
    ```