# RedirectRegex not working: www.subdomain.domain.com → subdomain.domain.com

**URL:** <https://community.traefik.io/t/redirectregex-not-working-www-subdomain-domain-com-subdomain-domain-com/15656>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [September 6, 2022, 7:02pm UTC](https://community.traefik.io/t/redirectregex-not-working-www-subdomain-domain-com-subdomain-domain-com/15656 "2022-09-06T19:02:38Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![kars-h](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/kars-h/32/5841_2.png) [@kars-h](https://community.traefik.io/u/kars-h)\
**Post date:** [September 6, 2022, 7:02pm UTC](https://community.traefik.io/t/redirectregex-not-working-www-subdomain-domain-com-subdomain-domain-com/15656/1 "2022-09-06T19:02:38Z")

</div>

Hey there, been puzzling with Traefik for the last few days.

I've got most things working except the my last redirect.

In the following file, the middleware to redirect for example `www.test.kennis.shop` to `test.kennish.shop` (remove the `www.` ) doesn't seem to work: it loads the URL including `www.` and throws an SSL error.

This is the traefik\_conf.yml:

```auto
http:
  routers:
   
    # load website with both domains
    kennisshop:
      service: subdomains
      priority: 1
      rule: "Host(`kennis.shop`, `smartclasses.app`)"
      tls:
        certResolver: leresolver
        domains:
          - main: "kennis.shop"
            sans:
              - "*.kennis.shop"
              - "smartclasses.app"
              - "*.smartclasses.app"

    # Redirects www.kennis.shop to kennis.shop - and loads subdomain with wildcard resolver
    kennisshop-www: 
      rule: "HostRegexp(`{subdomain:[a-z]+}.kennis.shop`) || HostRegexp(`{subdomain:[a-z]+}.smartclasses.app`)" # If the rule matches, apply the middleware
      service: subdomains
      middlewares: 
      - redirect-www-kennisshop
      - redirect-www-smartclasses
      priority: 2
      tls:
        certResolver: myresolver
        domains:
          - main: "kennis.shop"
            sans:
              - "*.kennis.shop"
              - "smartclasses.app"
              - "*.smartclasses.app"

    # Redirect all www.subdomain.kennis.shop to remove the www. - NOT WORKING
    kennisshop-www-subdomains: 
      priority: 3
      middlewares: 
      - redirect-www-subdomain-kennisshop
      - redirect-www-subdomain-smartclasses
      service: subdomains
      rule: "HostRegexp(`www.{subdomain:[a-z]+}.kennis.shop`) || HostRegexp(`www.{subdomain:[a-z]+}.smartclasses.app`)" 
      tls:
        certResolver: myresolver
        domains:
          - main: "kennis.shop"
            sans:   
              - "*.kennis.shop" 
              - "*.kennis.shop"
              - "smartclasses.app"
              - "*.smartclasses.app"
  
  services:
    subdomains:
      loadBalancer:
        servers:
          - url: "http://smartclasses.app:49154/"
  
  middlewares: ##define middlewares
  # remove www from kennisshop
    redirect-www-kennisshop: # remove www.
      redirectRegex:
        regex: "^https://www.kennis.shop/(.*)"
        replacement: "https://kennis.shop/${1}"
  # remove www from smartclasses
    redirect-www-smartclasses: # remove www.
      redirectRegex:
        regex: "^https://www.smartclasses.app/(.*)"
        replacement: "https://smartclasses.app/${1}"

    redirect-www-subdomain-kennisshop: ##redirect www.subdomain from kennis.shop
      redirectRegex:
        regex: "^https://www.{subdomain:[a-z]+}.kennis.shop/(.*)"
        replacement: "https://{subdomain:[a-z]+}.kennis.shop/${1}"
        permanent: true 

    redirect-www-subdomain-smartclasses: ##redirect www.sbudomain from smartclasses.app
      redirectRegex:
        regex: "^https://www.{subdomain:[a-z]+}.smartclasses.app/(.*)"
        replacement: "https://{subdomain:[a-z]+}.smartclasses.app/${1}"
        permanent: true 

```

I can see the middleware function well in the dashboard:

 ![image](https://us1.discourse-cdn.com/flex020/uploads/containo/original/2X/3/39efdcbce416677cd0be6061b9c724eb1d349057.png)

Also, the other redirect (from `www.kennis.shop` to `kennis.shop`) works perfectly.  
Any idea what's going wrong?

Not sure how to debug the exact steps Traefik is taking.
