# Traefik | More than 10 domains in a rule | Easier way needed?

**URL:** <https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143>\
**Category:** Traefik v2\
**Tags:** docker\
**Created:** [April 14, 2022, 8:47am UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143 "2022-04-14T08:47:26Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![mf1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mf1/32/5037_2.png) [@mf1](https://community.traefik.io/u/mf1)\
**Post date:** [April 14, 2022, 8:47am UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/1 "2022-04-14T08:47:26Z")

</div>

The normal way for a site is to define the hostnames like this.

` - "traefik.http.routers.nginx.rule=Host(`domain.com`, `www.domain.com`)"`

I have a project with about 10+ domains pointed to the service.... both with and without `www.` ... the configuration line will be larger and larger.

Is there an easier way to add all domains? Like a text file which can be used for both rules SSL and non-SSL, too?

---

<div class="post-metadata">

**Author:** ![tommoulard](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/tommoulard/32/2997_2.png) [@tommoulard](https://community.traefik.io/u/tommoulard)\
**Post date:** [April 15, 2022, 10:24am UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/2 "2022-04-15T10:24:09Z")

</div>

Hello @mf1,

I don't have a real solution for you, but you could try using the `HostRegexp` matcher, matching `(www.)?domain.com`. This way would allow defining a single host for both, thus cutting in half the definition size.

---

<div class="post-metadata">

**Author:** ![mf1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mf1/32/5037_2.png) [@mf1](https://community.traefik.io/u/mf1)\
**Post date:** [April 15, 2022, 11:50am UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/3 "2022-04-15T11:50:42Z")

</div>

Hi @tommoulard .

Your idea looks great and perfect for this project. In this scenario it could safe more than 50% of definitions....

Mainly there is one domain with different syntax's. In my example with optional plural "s", optional hyphen "-", optional "www." and of course different TLDs.

`- "traefik.http.routers.nginx.rule=HostRegexp(`(www.)?dom(-)?ain(s)?.(tld1|tld2|tld3|tld4)`)"`

I've tried the optional www version, too. But this isn't working. Do I need to install more something more?

---

<div class="post-metadata">

**Author:** ![tommoulard](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/tommoulard/32/2997_2.png) [@tommoulard](https://community.traefik.io/u/tommoulard)\
**Post date:** [April 15, 2022, 12:32pm UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/4 "2022-04-15T12:32:51Z")

</div>

I don't see any issues with your regexp : [regex101: build, test, and debug regex](https://regex101.com/r/Ozy1QB/1)  
You can use this tool to engineer a regexp that suits your needs 😄

---

<div class="post-metadata">

**Author:** ![mf1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mf1/32/5037_2.png) [@mf1](https://community.traefik.io/u/mf1)\
**Post date:** [April 15, 2022, 2:13pm UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/5 "2022-04-15T14:13:34Z")

</div>

I always get `404 page not found` from Traefik proxy. Even I used the smallest rule  
`- "traefik.http.routers.nginx.rule=HostRegexp(`(www.)?domain.com`)"`

Using ...  
`- "traefik.http.routers.nginx.rule=Host(`domain.com`, `www.domain.com`)"`  
... everything is working fine.

Using the more complex rule I get additional SSL issue because the LetsEncrypt certificate wasn't pulled, I guess.

It's really enough to just replace `Host` by `HostRegexp` parameter? No additional flag is needed?

---

<div class="post-metadata">

**Author:** ![tommoulard](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/tommoulard/32/2997_2.png) [@tommoulard](https://community.traefik.io/u/tommoulard)\
**Post date:** [April 15, 2022, 2:46pm UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/6 "2022-04-15T14:46:15Z")

</div>

It's because you are not using the correct format to define regexps in the `HostRegexp` matcher.  
You could have done this:

```yaml
    label:
      traefik.http.routers.nginx.rule: HostRegexp(`{wordwideweb:(www\.)?}domain.com`)

```

See _Regexp Syntax_ on [Traefik Routers Documentation - Traefik](https://doc.traefik.io/traefik/routing/routers/#rule)

---

<div class="post-metadata">

**Author:** ![mf1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mf1/32/5037_2.png) [@mf1](https://community.traefik.io/u/mf1)\
**Post date:** [April 15, 2022, 3:23pm UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/7 "2022-04-15T15:23:32Z")

</div>

Thanks. I've switched all the labels from "hyphen & quotes & equal" to "nothing & colon"  
Now it's working with the standard rule. www and non-www.

I also use curly bracket for each rule which is now also named

```auto
traefik.http.routers.nginx.rule: HostRegexp(`{worldwideweb:(www\.)?}dom{hyphen:(-)?}ain{plural:(s)?}.{tld:(tld1|tld2|tld3|tld3)}`)

```

Using the more complex rule the normal domain is working, also with SSL. All other domains showing `ERR_SSL_PROTOCOL_ERROR`. How can I solve this?

Additional: Is it needed to have unique Match names overall projects running this Traefik instance?

---

<div class="post-metadata">

**Author:** ![mf1](https://sea2.discourse-cdn.com/flex020/user_avatar/community.traefik.io/mf1/32/5037_2.png) [@mf1](https://community.traefik.io/u/mf1)\
**Post date:** [April 15, 2022, 6:01pm UTC](https://community.traefik.io/t/traefik-more-than-10-domains-in-a-rule-easier-way-needed/14143/8 "2022-04-15T18:01:23Z")

</div>

I've found the reason why this isn't working. LetsEncrypt isn't usable with HostRegexp. In this case I have to put all domains separately ... this is what I actually wanted to make easier... 😃
