How to do defaultRule: "HostRegexp" and compose file label rule=HostRegexp?

So I have a domain for my public site aljabal.dev and I use home.arpa for my local services.

I want to make it so that both are assigned to my services by default using defaultRule with container name or hostname or service name in traefik.yml and if I decide to set a specific name using labels in compose file or sablier file.

Currently, using self-signed certs only and haven’t setup traefik to use letsencrypt to generate *.aljabal.dev wildcard cert, but planning to do so soon.

what is working currently for me is below:

traefik.yml:

providers:
  docker:
    exposedByDefault: false
    defaultRule: "Host(`{{ index .Labels \"com.docker.compose.service\" }}.{{ env \"DOMAIN_LAN\" }}`)"

docker compose labels:

      - "traefik.http.routers.mediatracker.rule=Host(`${HOSTNAME_MEDIATRACKER}.${DOMAIN_LAN}`) || Host(`${HOSTNAME_MEDIATRACKER}.${DOMAIN_WAN}`)"

OR
      - "traefik.http.routers.mediatracker.rule=HostRegexp(`^${HOSTNAME_MEDIATRACKER}\\.(aljabal\\.dev|home\\.arpa)$$`)"

OR

- "traefik.http.routers.mediatracker.rule=HostRegexp(`^${HOSTNAME_MEDIATRACKER}\\.(${DOMAIN_LAN}|${DOMAIN_WAN})$$`)"

sablier-service.yml:

http:
  middlewares:
    sablier-dokuwiki:
      plugin:
        sablier:
          sablierUrl: http://sablier:10000
          sessionDuration: 10m
          names: dokuwiki
          dynamic:
            displayName: dokuwiki

  services:
    dokuwiki:
      loadBalancer:
        servers:
          - url: "http://dokuwiki:8080"

  routers:
    dokuwiki-dynamic-router::
      rule: 'Host(`dokuwiki.{{env "DOMAIN_LAN"}}`) || Host(`dokuwiki.{{env "DOMAIN_WAN"}}`)'
      service: "dokuwiki"
      entryPoints:
        - "websecure-lan"
      middlewares:
        - sablier-dokuwiki@file

How to do this using the vars and hostregexp? I don’t want to add labels to every service, only some. The rest should be using defaultrule.

I hate repeating same things in my configs, so I love using vars. Any more tips for that also is welcome.

Thank you.

    defaultRule: "HostRegexp(`^{{ .ContainerName }}\\.({{env \"DOMAIN_LAN\"}}|{{env \"DOMAIN_WAN\"}})$$`)"

This seems to work. My container name and hostname are same and i can access the services with that on home.arpa. haven’t tested .dev yet.

But i get below error in my traefik.log:

{
  "level": "warn",
  "entryPointName": "websecure",
  "routerName": "syncthing@docker",
  "time": "2026-01-09T12:32:19+05:30",
  "message": "No domain found in rule HostRegexp(`^syncthing-pi3\\.(home.arpa|aljabal.dev)$$`), the TLS options applied for this router will depend on the SNI of each request"
}
{
  "level": "warn",
  "entryPointName": "websecure",
  "routerName": "vikunja@docker",
  "time": "2026-01-09T12:32:19+05:30",
  "message": "No domain found in rule HostRegexp(`^vikunja\\.(home.arpa|aljabal.dev)$$`), the TLS options applied for this router will depend on the SNI of each request"
}

Can someone please confirm that this is a correct way to use hostregexp?

Traefik likes Host() more, because it has a clean domain name, can be used to create LetsEncrypt TLS domain certificates. Without a clear host you will get the warning.