Issues with Add Prefix - REGEX

Hi
In short here is what im trying to accomplish.
I have an application that is accessed with the following name and path: rock-stage.abc.com/webpage
I want the user to be redirected to rock-stage.abc.com/webpage automatically upon entering rock-stage.abc.com
In order to accomplish this i went ahead and used the middleware Add Prefix but it doesnt seem to work

Here is what my compose file looks like. If it manually enter the path i can navigate to it

version : "3.6"

services:
  Rock_stage:
    privileged: true
    logging:
      driver: json-file
    image: MYREGISTRYINFO
    networks:
      - traefik-net
    ports:
      - '10080:5040'
    environment:
      ENV: "stage"
    deploy:
      replicas: 10
      update_config:
        parallelism: 1
        delay: 10s
      labels:
        - "traefik.enable=true"
        - "traefik.http.routers.rock-stage.rule=Host(`rock-stage.abc.com`)"
        - "traefik.http.routers.rock-stage.entrypoints=web"
        - "traefik.http.routers.rock-stage.middlewares=add-Webpage"
        - "traefik.http.services.rock-stage.loadbalancer.server.port=5040"
        - "traefik.http.middlewares.add-Webpage.addPrefix.prefix=/Webpage"
networks:
  traefik-net:
    external: true

I dont see any errors in traefik, i also went ahead and removed


- "traefik.http.routers.rock-stage.middlewares=add-Webpage"

But this doesnt seem to help either

The middleware https://docs.traefik.io/middlewares/redirectregex/#redirectregex is what you want to be using. This does the browser redirect you are expecting.

The addPrefix adds the prefix before sending it to the backend.

Thanks for pointing me in the right direction. Heres what i have so far but i feel like im stuck again.
I checked my REGEX several times and it seems to be good, not sure what the problem may be.
Any help will be appreciated

        - "traefik.enable=true"
        - "traefik.http.routers.rock-stage.rule=Host(`rock-stage.abc.com`)"
        - "traefik.http.routers.rock-stage.entrypoints=web"
        - "traefik.http.routers.rock-stage.middlewares=test"
        - "traefik.http.services.rock-stage.loadbalancer.passhostheader=true"
        - "traefik.http.services.rock-stage.loadbalancer.server.port=5040"
        - "traefik.http.middlewares.test.redirectregex.regex=^(.*)"
        - "traefik.http.middlewares.test.redirectregex.replacement=$${1}/Webpage"
        - "traefik.http.middlewares.test.redirectregex.permanent=true"

Feels like im missing something really simple here ...

Without testing this my self I am guessing this will redirect every single time. Eventually hitting a redirect limit.

http://rock-stage.abc.com/ -> http://rock-stage.abc.com/Webpage
http://rock-stage.abc.com/Webpage - > http://rock-stage.abc.com/Webpage/Webpage
...

Lock the regex down to ^http://rock-stage.abc.com/$
And replace to $${0}Webpage

1 Like

You were correct. The issue is now resolved. Thanks! Appreciate all your help
Here are my updated labels:

- "traefik.http.routers.rock-stage.middlewares=test"
- "traefik.http.middlewares.test.redirectregex.regex=^http://irock-stage.abc.com/?$$"
- "traefik.http.middlewares.test.redirectregex.replacement=http://irock-stage.abc.com/Webpage/"
- "traefik.http.middlewares.test.redirectregex.permanent=true"
1 Like