Explanation of other useful contributed modules:
For certain situations, the Domain Module suite works really well. Our testing found it a bit too heavy handed with how it handled fields in the database. We opt for a simpler Taxonomy Term to hold "Affiliated Site" information.
The Domain Theme Switching module is useful for swapping designs based on DNS. We opted for using Drupal's core taxonomy terms over the Theme Switching sub-module. By combining Site Terms, Twig Templates and a well planned URL Schema, a single theme can be used with out the need to swap in a full theme. With the the Terms approach, theme elements auto-magically swap based on the current Affiliated site being viewed. ( Example: logo_{site_term}_large.svg )
Explain using "Virtual Hosts" in an Apache.conf to set a variable based on the inbound an DNS values:
If hosting with Apache, there can be an advantage to setting a site's Domain at the webserver level. This technique assumes that you are maintaining DNS records for each Affiliate Site. Your mileage may vary depending on your Host and Webserver. (The Nginx webserver may be able to pass PHP variable too. ?)
// Apache Conf Example for a Virtual Host section
ServerName snowmaid.com
ServerAlias snowmaid.com # Set the DOMAIN variable to the current domain name
SetEnvIf Host "(.*)" DOMAIN_NAME=$1
RequestHeader set X-Forwarded-Proto "https"
// This example can go into the settings.php for your site
// Set the domain name based on the Apache variable.
$domain_name = $_SERVER['DOMAIN_NAME'] ?? NULL;
// Set the domain name to 4 if DOMAIN_NAME is empty.
if (empty($domain_name)) {
$domain_name = "gluebox.com"
}
// Set the domain name as a Drupal environment variable.
putenv("DOMAIN_NAME=$domain_name");
Map the DOMAIN_NAME environment variable to a custom site name based on its value.
By setting the site name dynamically using the DOMAIN_NAME environment variable, different site names are set based on the inbound domain. Brands the user experience where multiple sites are served from a single Drupal installation.
// Set custom site name based on DOMAIN_NAME environment variable.
$site_name = '';
switch ($domain_name) {
case 'snowmaid.com':
$site_name = 'SnowMaid Outdoor Adventures';
break;
case 'gluebox.com': $site_name = 'Gluebox Technology';
break;
case 'dankspine.com': $site_name = 'Dank Spine';
break;
// Add more cases for other domain names if needed.
default: $site_name = 'GlueBox Technology';
break; }
$config['system.site']['name'] = $site_name;