Roots Discourse

Multiple domain forwarding in Trellis

Hello,

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.

wordpress_sites:
  example.com:
    site_hosts:
      - canonical: example.com
        redirects:
          - example.fr
          - www.example.fr
          - example.eu
          - www.example.eu
          - example.pt
          - www.example.pt
    local_path: ../site # path targeting local Bedrock site directory (relative to Ansible root)
    repo: git@github.com:example/example.com.git # replace with your Git repo URL
    repo_subtree_path: site # relative path to your Bedrock/WP directory in your repo
    branch: master
    multisite:
      enabled: false
    ssl:
      enabled: false
      provider: letsencrypt
    cache:
      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.

Swann

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 www.example.fr to the IP address example.fr 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: https://github.com/roots/trellis/blob/8661144e847c1c7e6d4119d194958c295516cb1b/roles/wordpress-setup/templates/wordpress-site.conf.j2#L280-L305 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 ¯\(ツ)

2 Likes

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.