# How do I rewrite a path based on the request's host?

**URL:** <https://community.traefik.io/t/how-do-i-rewrite-a-path-based-on-the-requests-host/5192>\
**Category:** Traefik v2\
**Tags:** middleware\
**Created:** [March 30, 2020, 12:34pm UTC](https://community.traefik.io/t/how-do-i-rewrite-a-path-based-on-the-requests-host/5192 "2020-03-30T12:34:29Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![m90](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/m90/32/1817_2.png) [@m90](https://community.traefik.io/u/m90)\
**Post date:** [March 30, 2020, 12:34pm UTC](https://community.traefik.io/t/how-do-i-rewrite-a-path-based-on-the-requests-host/5192/1 "2020-03-30T12:34:29Z")

</div>

I have a situation where I would like to pass a request like `https://something-dynamic.mydomain.com/resource/` to `http://internal-service/something-dynamic/resource/`

Yet, from reading the documentation I **cannot** find any way to:

1. Use the match from my router's `HostRegexp` rule in a middleware (e.g. `addPrefix`)
2. Read the Host or Host Header in a `ReplacePathRegex` middleware
3. Use any of the `Redirect*` middleware without issuing a 30\* response

Is this even possible with Traefik?

For the sake of completeness, this is what I would like to do in configuration:

```auto
[http]
  [http.routers]
    [http.routers.demo]
      rule = "HostRegexp(`{bucketName:[a-z\\-]+}.demo.localhost`)"
      middlewares = ["addBucket"]
      service = "demo"

  [http.middlewares.addBucket]
    [http.middlewares.addBucket.addPrefix]
      # this obviously does not work
      prefix = "/{bucketName}/"

  [http.services]
    [http.services.demo.loadBalancer]
      passHostHeader = false
      [[http.services.demo.loadBalancer.servers]]
        url = "http://my-resource.s3-website.eu-central-1.amazonaws.com/"

```
