# Router Host regex variable re-use

**URL:** <https://community.traefik.io/t/router-host-regex-variable-re-use/1935>\
**Category:** Traefik v2\
**Tags:** file\
**Created:** [September 26, 2019, 7:53pm UTC](https://community.traefik.io/t/router-host-regex-variable-re-use/1935 "2019-09-26T19:53:36Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![vaughnmb](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@vaughnmb](https://community.traefik.io/u/vaughnmb)\
**Post date:** [September 26, 2019, 7:53pm UTC](https://community.traefik.io/t/router-host-regex-variable-re-use/1935/1 "2019-09-26T19:53:36Z")

</div>

Is it possible to use the variable in the regex between routers and services in Traefik 2.0? I saw a similar question for Traefix 1.x, but I didn't know if the feature was added.

```auto
  routers:
    test:
      entryPoints:
        - "http"
        - "https" 
      rule: "Host(`test.{domain:(app|dev)}.blah.com`) || Host(`test.{domain:(app|dev)}.blah.com`)"
      service: test
  services:
    test:
      loadBalancer:
        servers:
          - url: "https://test.$domain.blah.com:81/"

```

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 27, 2019, 3:05am UTC](https://community.traefik.io/t/router-host-regex-variable-re-use/1935/2 "2019-09-27T03:05:25Z")

</div>

Hello,

I recommend to use the redirectRegex middleware: [https://docs.traefik.io/v2.0/middlewares/redirectregex/](https://docs.traefik.io/v2.0/middlewares/redirectregex/)

---

<div class="post-metadata">

**Author:** ![vaughnmb](https://avatars.discourse-cdn.com/v4/letter/v/b3f665/32.png) [@vaughnmb](https://community.traefik.io/u/vaughnmb)\
**Post date:** [September 27, 2019, 6:28pm UTC](https://community.traefik.io/t/router-host-regex-variable-re-use/1935/3 "2019-09-27T18:28:30Z")

</div>

I implemented the RedirectRegex. It will only work on http commands, but not on https? Is it not possible to redirect on https? Below is my config

```auto
http:
  middlewares:
    https-redirect:
      redirectScheme:
        scheme: https
    dfp-redirect:
      redirectRegex:
        regex: "^http://(.*).company.com"
        replacement: "http://${1}.company.com:81"
    dfpssl-redirect:
      redirectRegex:
        regex: "^https://(.*).company.com"
        replacement: "https://${1}.company.com:444"
  routers:
    test:
      entryPoints:
        - "http"
        - "https" 
      rule: "HostRegexp(`test.{domain:(app|dev)}.company.com`)"
      middlewares:
        - dfpssl-redirect
        - dfp-redirect
      service: anything
  services:
    anything:
      loadBalancer:
        servers:
        - url: "http://fake/"

```

---

<div class="post-metadata">

**Author:** ![ldez](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/ldez/32/5_2.png) [@ldez](https://community.traefik.io/u/ldez)\
**Post date:** [September 27, 2019, 6:37pm UTC](https://community.traefik.io/t/router-host-regex-variable-re-use/1935/4 "2019-09-27T18:37:25Z")

</div>

In the v2 the TLS is on the router [https://docs.traefik.io/v2.0/routing/routers/#tls](https://docs.traefik.io/v2.0/routing/routers/#tls)
