Multiple domain forwarding in Trellis


I am developing a site for a client and the setup is a little bit more complex than what I am used to. They bought various domain extensions to which .com is the canonical one.

      - canonical:
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    repo: # replace with your Git repo URL
    repo_subtree_path: site # relative path to your Bedrock/WP directory in your repo
    branch: master
      enabled: false
      enabled: false
      provider: letsencrypt
      enabled: false

Do I really need to write these 6 redirects to handle all the cases?
Is it possible to use a regex such as (www.)?example.(fr|eu|pt)
Or something similar?

I am not really sure I am doing it right, I would appreciate a quick feedbacks to point me in the right direction.


Is there a reason you can’t do those redirects at the DNS level and then only worry about the canonical domain on the server?

1 Like

My ignorance is probably the only reason.
I did setup a CNAME for all www for each extension.

From my understanding it does not rewrite, it just merely route to the IP address is pointing to.

So I still need to tell my Trellis how to redirect, no?

Based on my (admittedly limited) understanding of the Trellis role that generates redirects, Trellis will also just redirect to the cannonical URL, not do rewrites: If you need re-writes I think you’ll need to dig into the nginx config a little bit.

If all you want is a regex for redirect, it looks like you might be able to do that. It looks like Trellis is just iterating over the items in redirects, so in theory I think you could put a single item in there that contains a properly-formatted regex that nginx understands. That’s just based on 5 minutes of Googling though, not actual experience, so ¯\(ツ)


Alright I still have no idea how CNAME works under the hood but remove all the redirects lines with the “www” and replaced all the others by a regex. It works.

Hi @soueuls, do you mind sharing the regex you used?

Hello @JordanC26,

I finally decided to stay away from using regex inside the Trellis config.

This topic was automatically closed after 42 days. New replies are no longer allowed.