# Application URL write behind Traefik as Reverse Proxy possible?

**URL:** <https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605>\
**Category:** Traefik v2\
**Tags:** middleware, docker\
**Created:** [April 21, 2020, 7:15am UTC](https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605 "2020-04-21T07:15:48Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![stdevel](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/stdevel/32/1950_2.png) [@stdevel](https://community.traefik.io/u/stdevel)\
**Post date:** [April 21, 2020, 7:15am UTC](https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605/1 "2020-04-21T07:15:48Z")

</div>

Hi everybody,

I'm trying to setup Traefik 2.2.0 as Reverse Proxy for some containers. In detail, I'm running two web applications that I want to expose via dedicated directories `/app1` and `/app2`.

I figured out how to set-up a middleware to strip `/app2` from the URL before passing the request to the application. Otherwise the request results in a 404 error as `GET /` is replaced by `GET /app2/`.

Anyhow, the application has links on the landing page (_e.g. `/pageA`, `/pageB`,..._). Clicking on one of the links of course results in a 404 error as the URLs are not rewritten.

My question now is - how can I implement this URL rewriting?

Any hints or tips are welcome - I'm quite new to Traefik and reverse proxies in general. 🙂

**What I tried**  
I tried to assign `redirectregex` and `replacepathregex` middlewares to the application - with or without the `stripprefix` middleware:

```yaml
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.radio.rule=Host(`192.168.0.246`) && PathPrefix(`/app2`)"
      - "traefik.http.routers.radio.entrypoints=web"
      - "traefik.http.middlewares.radio_strip_prefix.stripprefix.prefixes=/app2"
      - "traefik.http.middlewares.test-replacepathregex.replacepathregex.regex=^/app2/(.*)"
      - "traefik.http.middlewares.test-replacepathregex.replacepathregex.replacement=/$$1"
      - "traefik.http.routers.radio.middlewares=radio_strip_prefix@docker,test-replacepathregex@docker"
      #- "traefik.http.routers.radio.middlewares=test-replacepathregex@docker"

```

```yaml
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.radio.rule=Host(`192.168.0.246`) && PathPrefix(`/app2`)"
      - "traefik.http.routers.radio.entrypoints=web"
      - "traefik.http.middlewares.radio_strip_prefix.stripprefix.prefixes=/app2"
      - "traefik.http.routers.radio.middlewares=radio_strip_prefix@docker,test-redirectregex@docker"
      - "traefik.http.routers.radio.middlewares=test-redirectregex@docker,replacepathregex@docker"
      #- "traefik.http.routers.radio.middlewares=test-redirectregex@docker"

```

None of them were working as expected.

**Environment**

- Traefik 2.2.0 Docker Container
- Docker CE 19.03 (armhf)
- two Docker web applications

**Dockerfile**

```yaml
version: "3.7"

services:
  traefik:
    image: traefik:2.2
    container_name: traefik
    command:
      - "--api.insecure=true"
      - "--providers.docker"
      - "--providers.docker.exposedbydefault=false"
      - "--entrypoints.web.address=:80"
    ports:
      - "80:80"
      - "8080:8080"
    volumes:
      - /var/run/docker.sock:/var/run/docker.sock:ro
  whoami:
    image: containous/whoami
    container_name: whoami
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.whoami.rule=Host(`<ip-address>`) && PathPrefix(`/app1`)"
      - "traefik.http.routers.whoami.entrypoints=web"
  radio:
    image: stdevel/radio_api
    container_name: radio_dev
    labels:
      - "traefik.enable=true"
      - "traefik.http.routers.radio.rule=Host(`<ip-address>`) && PathPrefix(`/app2`)"
      - "traefik.http.routers.radio.entrypoints=web"
      - "traefik.http.middlewares.radio_strip_prefix.stripprefix.prefixes=/app2"
      ##- "traefik.http.routers.radio.middlewares=radio_strip_prefix@docker"
      #- "traefik.http.routers.radio.middlewares=radio_strip_prefix@docker,test-redirectregex@docker"
      #- "traefik.http.routers.radio.middlewares=test-redirectregex@docker"
      - "traefik.http.middlewares.test-replacepathregex.replacepathregex.regex=^/app2/(.*)"
      - "traefik.http.middlewares.test-replacepathregex.replacepathregex.replacement=/$$1"
      - "traefik.http.routers.radio.middlewares=radio_strip_prefix@docker,test-replacepathregex@docker"

```

---

<div class="post-metadata">

**Author:** ![evdel](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evdel](https://community.traefik.io/u/evdel)\
**Post date:** [November 19, 2020, 6:48pm UTC](https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605/2 "2020-11-19T18:48:27Z")

</div>

Hello

I am trying to do the same thing as you.

From what I have seen so far there is no way to do it only using Traefik.

Though some applications can be configured to run behind a reverse proxy using an url prefix, like discussed about Grafana for example : [Why doesn't traefik readd PathPrefix prefixes to backend responses?](https://community.traefik.io/t/why-doesnt-traefik-readd-pathprefix-prefixes-to-backend-responses/1240)

---

<div class="post-metadata">

**Author:** ![stdevel](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/stdevel/32/1950_2.png) [@stdevel](https://community.traefik.io/u/stdevel)\
**Post date:** [November 22, 2020, 6:47pm UTC](https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605/4 "2020-11-22T18:47:11Z")

</div>

Hey evdel,  
that's interesting - thanks for sharing!

Best wishes,  
Christian.

---

<div class="post-metadata">

**Author:** ![evdel](https://avatars.discourse-cdn.com/v4/letter/e/85f322/32.png) [@evdel](https://community.traefik.io/u/evdel)\
**Post date:** [January 25, 2021, 5:44pm UTC](https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605/5 "2021-01-25T17:44:51Z")

</div>

You're welcome. Finally I ended up creating one sub-domain for the other app I wanted to expose.

I think it is the simplest solution. Why not having something like [app1.domain.com](http://app1.domain.com) and [app2.domain.com](http://app2.domain.com) for example ?

Cheers

---

<div class="post-metadata">

**Author:** ![MGasztold](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mgasztold/32/5537_2.png) [@MGasztold](https://community.traefik.io/u/MGasztold)\
**Post date:** [June 30, 2022, 12:42pm UTC](https://community.traefik.io/t/application-url-write-behind-traefik-as-reverse-proxy-possible/5605/6 "2022-06-30T12:42:47Z")

</div>

Hello, Have you solved the problem with /paths? I am struggling with it as well. I want to have Hashicorp Nomad UI at [https://mydomain.com/nomad](https://mydomain.com/nomad), no successes so far.

> **[Put Nomad UI behind traefik reverse proxy](https://discuss.hashicorp.com/t/put-nomad-ui-behind-traefik-reverse-proxy/41452)**
>
> I am trying to make Nomad UI work when behind a Traefik reverse proxy that uses a path address. I want to use https://mydomain.com/nomad and similarly consul https://mydomain.com/consul I have configured Nomad service in Traefik in the following...
