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

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:

[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/"