Display different modules on different subdomains

(5 votes, average 4.60 out of 5)

In this scenario you have a number of subdomains all pointing into the same main domain. e.g. www.example.com, alabama.example.com, alaska.example.com. You want to have different modules displayed on each of the different domains, even though the main content of the pages is the same for each. How do you do it?

Don’t forget to customise the module IDs that you are returning, to match the IDs of your own modules.

With JomGenius

This technique is available from MetaMod 2.4 onwards.
// replace UUU-ZZZ with the module IDs to return for each domain.
if ( $core_genius->check("domain = alabama.example.com" ) ) return UUU;
if ( $core_genius->check("domain = alaska.example.com" ) ) return VVV;
if ( $core_genius->check("domain = hawaii.example.com" ) ) return WWW;
if ( $core_genius->check("domain = texas.example.com" ) ) return XXX;
if ( $core_genius->check("domain = washington.example.com" ) ) return YYY;
if ( $core_genius->check("domain ends with .example2.com" ) ) return ZZZ;

If you simply want to get hold of the domain name into a variable for further processing, you can do this:

$domain = $core_genius->info("domain");

Pre-JomGenius

If you have MetaMod 2.4 or more recent, try the "JomGenius" version instead of this one.
$domain = $_SERVER['HTTP_HOST'];
switch($domain) {
 case "alabama.example.com": return 55;
 case "alaska.example.com": return 56;
 case "hawaii.example.com": return 57;
 case "texas.example.com": return 58;
 case "washington.example.com": return 59;
 /* etc etc.... */
}