HostRegexp example is very hard to understand

I honestly don't understand this from the documentation:
HostRegexp(, {subdomain:[a-z]+}, ...)
Is "subdomain" part of the string? like, what's going on? It would be awesome if the documentation was clearer.

(oh and, the "tags" still don't make any sense. This question isn't really specific to kubernetes-ingress)

I did not check that with v2, but if that something has not changed from v1 then subdomain is just an arbitrary string that has no bearing on how the expression parsed. It has to be present, but its content can be anything. I understand this is because how regexp engine used behind the scenes wants it. It also confused me when I came across this for the first time.

UPDATE: I just checked it's explained in the v2 doc here:

Sorry to bring this up, but I'm also struggling with this.

Not because of the regex definition, but because of the variable scope.

In v1 I was using the variable defined in HostRegexp with an addprefix
While migrating to v2, it doesn't look to work anymore, as if the variable defined in the regex was out of scope for the middleware.

#V1 + docker compose
- "traefik.frontend.rule=HostRegexp:{subdomain:[a-z0-9]+}.${HOSTNAME}"
- "traefik.frontend.addPrefix={subdomain}"
#V2 not working
- traefik.http.routers.sf14.rule=HostRegexp(`{subdomain:[a-z0-9]+}.${HOSTNAME}`)
- traefik.http.middlewares.sf14-addprefix.addprefix.prefix={subdomain}
- traefik.http.routers.sf14.middlewares=sf14-addprefix@docker

I lookup for variable usage but did only find stuff about environnement variables.

Is it still achievable in v2 and what is the scope of a variable defined in a HostRegexp rule ?

This doesn't work in v1 because there are no variable and traefik.frontend.addPrefix don't exist.

So it doesn't work in v2 for the same reason.

1 Like

You're perfectly right, I just re-tested this misleading configuration and it did not work.
That's why "dead code" is worst than anything...
Sorry for the bad dump.

I am also facing an issue with v2 and Hostregex at the moment:

    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=HostRegexp(`{subdomain:[a-z0-9]+}.${PROJECT_BASE_URL}`)"

Is not working, but for some reason this works fine:

    - "traefik.http.routers.${PROJECT_NAME}_nginx.rule=Host(`example.${PROJECT_BASE_URL}`)"

Any idea what is going wrong here?

Here everything is right. Wrong is somewhere else. :wink:

- "traefik.http.routers.${ROUTER_NAME}.rule=Host(`${DOMAIN}`) || HostRegexp(`{subdomain:[az0-9]+}.${DOMAIN}`)"

should do the trick

Little mistake. You have there az - but should be a-z :wink: hope it will save some debugging for someone