Multidomain multisite without a domain mapping plugin

I stumbled upon this WP.org support thread and tried the solution…

Go to Network Admin → Sites → Edit Site → edit the site URL.

It appears to work smoothly. No issues with SSLs.

One added step I needed to perform was adding these lines to the bottom of my Bedrock site config @ site/config/application.php:

define('ADMIN_COOKIE_PATH', '/');
define('COOKIE_DOMAIN', '');
define('COOKIEPATH', '');
define('SITECOOKIEPATH', '');

Without those additions I couldn’t login to my subsite (source).

There’s been a lot of chatter on this board lately between devs running Trellis + Multisite + Multidomain setups (@Simeon @darjanpanic @Foazino @colinob1 @cclass @rhud @JSDieNeu @DemaniClassic @daniel @juanmaguitar @Helen_Humphrey) and I’d love to put this out there and see if anyone else has tried this long term and any problems you may have encountered.

5 Likes

Seems interesting, thanks. Were there any steps added before that? Or does this work only without Trellis?

I tried it on my local Trellis (and pointed the domain to the vagrant ip via etc/hosts) but got an err_response. I guess i’d need to add the domain also to the nginx conf/wordpress_sites etc. for it to work.

I think the feature most of us want/need is that we don’t want to manually tinker with hosts, nginx, let’s encrypt every time a mapped domain is created. Reason is, well if you get 1k subscribers (and we really do want to get these to a saas) then domain mapping becomes a feature that would need to work automagically for the user and us. Imagine doing manual changes/deploys for each of those users.

A Free SSL brings a lot of value to the new user and his domain as these are usually quite hard to setup by a basic user. And they really love the words secure, free and SEO benefits when you promote this feature with your service :slight_smile:

A let’s encrypt solution could be that there is a list of domain mappings which it pulls and install via server cron maybe each day or 12 hours.

I will try couple of things in the next week or two and share my findings or ways on how to do this cleanly.

1 Like

Interesting that you mention your local config because I’ve been unable to get any domain mapping working locally whatsoever, either with the WP MU plugin or Mercator—even with landrush active and apparently working. This method (without a mapping plugin) isn’t working either, but on my remote it works a treat.

In my remote’s wordpress_sites.yml I did add the domain to be mapped. I added the initial subdomain too but I don’t think that’s necessary and I will try a reprovision from scratch without it and confirm but I need to wait a few days so my LE certificates don’t get throttled.

Well add to that the http://subsite.multisite.dev works nicely with landrush out of the box and these subdomains don’t need anything in wordpress_sites.yml to work. In a way they are different things then domain mapping but the functionality we want to achieve seems to be similar. :slight_smile:

So your solution at the top seems amazingly easy and the right way to do it too. I’ll also try some things on the live server.

@cfx I could not get any domain mapping plugins to work at all with Trellis, but the solution you suggest is exactly the solution that is working perfectly on my end as well. Add the domain to the wordpress_sites.yml, deploy and then change the url in settings, and you are good to go. This has been operational on a production site with three domains for 2-3 months now. And I just added another site / domain last week to the network with the same procedure. Since I am not allowing users to create sites, this is all I need.

1 Like

@colinob1 that’s great to hear, thanks for sharing!

What are you doing with your local environment for testing?

I can’t, for the life of me, get a subsite on a new domain to even resolve in my terminal unless I manually add it to my /etc/hosts file. $ vagrant landrush list correctly shows the subsite domain entry and its ip matches my vm’s ip and my main site’s ip. When I ping this second domain in my terminal it doesn’t resolve, citing “unknown host”.

@cfx I just use simple subdomains like site.domain.test, site2domain.test, etc. which works fine out of the box. I started running into problems with URLs like .dev, because they are now legit TLDs. Otherwise, my experience for local dev mirrors @darjanpanic. No /etc/host additions and no need to add subsites to wordpress_sites.yml.

@colinob1 makes sense, thank you again.

Hi guys,

this post was really useful, I will share what I have done for other newbies like me going through the process. Please correct me if something could have been done a better way !

Once Trellis installed and multisite ready on example.dev, I have added site2.example.dev via the wordpress admin.
At this stage, I have added site2.example.dev to my etc/hosts file and site2.example.dev worked well.

Then, I have added - canonical: site2.dev on my wordress_sites.yml file (dev) and launch vagrant provision.

Once ready, I went back to example.dev on the network admin and changed the url of site2 for http://site2.dev, I have updated my host file accordingly and that was it !

Will now force the redirect to www :slight_smile:

I have it working with some issues…
Only the first domain’s URL works the other ones need to be added to the /etc/hosts file. Even though vagrant landrush ls shows all the domains redirecting to the VM’s IP.

The Stage Switcher plugin seems to be out of whack… May not be related.

Loving the possibilities! I have several small sites that I’m not very interested in maintaining individually :slight_smile:

Bump.

Can someone smarter than me tell me if there’s any way around adding each new site in the network’s domain name to wordpress_sites, re-provisioning the server and deploying?

It’s not a difficult thing to do individually, but it’s not really scale-able. Wondering if there’s a way of off-setting the task of updating nginx to accept connections from the new domain.

I’ve got a subdirectory network so ideally the SSL comes from the main site’s URL anyway.

Edit: Like how do Squarespace absolutely shopify do this stuff? Guessing they have programmed to update their nginx conf (or similar) on account signup?

i am looking for a solution to this. did your work it out? i want to be able to add sites to a trellis mu wp network that have their own domain without having to add new sites in trellis config and re-provision, is this even possible?

Not that I’ve found. I’ve had to keep reprovisioning and deploying each time.

Just tried to add a different domain to a subsite on my network, and it seems I was successful, but it was a little bit tricky, and thought it would be helpful to share.

So getting inspiration from this thread, this is what I did:

  1. Added a A record to the “different domain” and to a subdomain originating from the main site.
  2. Added the cookie defines to config/application.php from the OP.
  3. Added the different domain as canonical, and that subdomain as redirect to wordpress_sites.yml (not totally sure if this is needed, might be tested without this). Provisioned the server.
  4. Added the new subsite with the subdomain. After that, edited the URL to the “different domain”

And at this point I thought everything should work, but the login did not yet. So checked around, and found out that in the database in the subsite’s wp_options table only the home key’s value was altered by modifying the URL in the network admin and the siteurl was not. So I modified that one too, and the login began to work!