# Traefik redirect to different subdomains

**URL:** <https://community.traefik.io/t/traefik-redirect-to-different-subdomains/12161>\
**Category:** Traefik v2\
**Tags:** file\
**Created:** [October 19, 2021, 1:44pm UTC](https://community.traefik.io/t/traefik-redirect-to-different-subdomains/12161 "2021-10-19T13:44:59Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mkaranlik](https://avatars.discourse-cdn.com/v4/letter/m/bbce88/32.png) [@mkaranlik](https://community.traefik.io/u/mkaranlik)\
**Post date:** [October 19, 2021, 1:44pm UTC](https://community.traefik.io/t/traefik-redirect-to-different-subdomains/12161/1 "2021-10-19T13:44:59Z")

</div>

Hello,  
I am trying to redirect requests from my traefik to different subdomains with respect to header info. For example; If [https://urltocall.com/subd/api/](https://urltocall.com/subd/api/) is called, I want traefik forward this request to [https://subd.urltocall.com/api/](https://subd.urltocall.com/api/). To achieve this I wrote a redirectRegex middleware and called this under my router. But I am having trouble with url under my service's loadbalancer section. I am giving my dynamic configuration yaml below. And I am having http: _TLS handshake error from 172.22.0.1:54800: remote error: tls: unknown certificate_ error in my traefik.log and 404 page not found on browser. Thanks for your valuable ideas.

dynamic\_conf.yml

```auto
http:
  routers:
    router-redirect:
      entryPoints:
      - ep-redirect
      tls:
        domains:
          - main: "*.urltocall.com"                 
      rule: "PathPrefix(`/{regex:$$|.*}`)"
      middlewares:
        - mw-redirectregex 

  middlewares:
    mw-redirectregex:
      redirectRegex:
        regex: "^https:\/\/urltocall.com\/(.*)\/(.*)\/"
        replacement: "https://$1.urltocall.com/$2/"
        permanent: false      

  services:
    service-redirect:
      loadBalancer:
        servers:
          - url: https://subd.urltocall.com/api/
        passHostHeader: false
        healthCheck:
          path: /
          interval: "10s"
          timeout: "5s"

```
