Hostregexp for All subdomains

Hi, there
I'd like to redirect all requested from *.subdomain.domain.com to some app.
For example: User go to URL aaa.subdomain.domain.com or bbb.subdomain.domain.com, but an application should works on all subdomains *.subdomain.domain.com

What I should to write?
traefik.http.routers.apihand-web-secure.rule=hostregexp({host:[a-z-.]+})

Hello @knock,

Based on the Routers section of our documentation: (https://docs.traefik.io/v2.1/routing/routers/#rule), you can use:

HostRegexp(`subdomain.domain.com`,`{subhost:[a-z]+}.subdomain.domain.com`)

But note that regex only works with lowercase letters.

You can use: {subhost:[a-zA-Z0-9-]+} to select capitals and numbers and dashes in your host.

I would avoid matching a period, as you may find issues down the road when you enable TLS (as a certificate for *.example.com will match www.example.com but not `test.www.example.com)

1 Like

Thank you Daniel!
It works!

1 Like