# Issues with Add Prefix - REGEX

**URL:** <https://community.traefik.io/t/issues-with-add-prefix-regex/6054>\
**Category:** Traefik v2\
**Tags:** docker, docker-swarm\
**Created:** [May 14, 2020, 3:25pm UTC](https://community.traefik.io/t/issues-with-add-prefix-regex/6054 "2020-05-14T15:25:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![contra](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/contra/32/2066_2.png) [@contra](https://community.traefik.io/u/contra)\
**Post date:** [May 14, 2020, 3:25pm UTC](https://community.traefik.io/t/issues-with-add-prefix-regex/6054/1 "2020-05-14T15:25:35Z")

</div>

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](http://rock-stage.abc.com/webpage)  
I want the user to be redirected to [rock-stage.abc.com/webpage](http://rock-stage.abc.com/webpage) automatically upon entering [rock-stage.abc.com](http://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

```auto
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

```auto

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

```

But this doesnt seem to help either

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [May 14, 2020, 4:26pm UTC](https://community.traefik.io/t/issues-with-add-prefix-regex/6054/2 "2020-05-14T16:26:53Z")

</div>

The middleware [https://docs.traefik.io/middlewares/redirectregex/#redirectregex](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.

---

<div class="post-metadata">

**Author:** ![contra](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/contra/32/2066_2.png) [@contra](https://community.traefik.io/u/contra)\
**Post date:** [May 14, 2020, 5:55pm UTC](https://community.traefik.io/t/issues-with-add-prefix-regex/6054/3 "2020-05-14T17:55:15Z")

</div>

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

```auto
        - "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 ...

---

<div class="post-metadata">

**Author:** ![cakiwi](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/cakiwi/32/3205_2.png) [@cakiwi](https://community.traefik.io/u/cakiwi)\
**Post date:** [May 14, 2020, 7:26pm UTC](https://community.traefik.io/t/issues-with-add-prefix-regex/6054/4 "2020-05-14T19:26:20Z")

</div>

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/) -\> [http://rock-stage.abc.com/Webpage](http://rock-stage.abc.com/Webpage)  
[http://rock-stage.abc.com/Webpage](http://rock-stage.abc.com/Webpage) - \> [http://rock-stage.abc.com/Webpage/Webpage](http://rock-stage.abc.com/Webpage/Webpage)  
...

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

---

<div class="post-metadata">

**Author:** ![contra](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/contra/32/2066_2.png) [@contra](https://community.traefik.io/u/contra)\
**Post date:** [May 14, 2020, 9:05pm UTC](https://community.traefik.io/t/issues-with-add-prefix-regex/6054/5 "2020-05-14T21:05:41Z")

</div>

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

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

```
