Skip to content
Adds support for subsites run from separate domain, but using single database (same admin site and user database).
Branch: master
Clone or download
Pull request Compare This branch is 20 commits ahead of apeisa:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
LICENSE.txt Some bug fixing with parsing url and redirecting Sep 29, 2016
Multisite.module added more url cases Dec 18, 2018
README.md

README.md

Multisite module for Processwire (WIP)

The basic module was written by Antti Peisa and forked by Philipp "Soma" Urlich ("there's not much left from the original module, but the basic concept is the same").

What does this module do?

It allows you to run multiple sites with different domains from a single install, using the same database. While you can easily do "subsites" like www.domain.com/campaign/, this allows you to turn that into www.campaign.com. This is nice stuff when you have multiple simple sites which all belong to the same organisation and which the same people maintain.

Isn't there multisite support in core?

Yes, kind of. It is very different from this. It allows you to run multiple pw-installations with shared core files (/wire/ folder). This is totally different: this is a single pw-installation which has multiple sites running from different domains.

How to use it?

Just create pages with names like www.campaigndomain.com unter the root page and add these in the config.php via an array in $config->MultisiteDomains.

This allows for different domain configurations on different environments like dev and live stage, and since it's not in DB (via the module config) it can be easily transfered with a dump without worrying to overwrite or change the settings.

Also there's no need to change the domain "root" pages name, as it's not directly coupled to the requesting domain. So you only change the array keys (=domain).

Add MultisiteDomains

Live environment

$config->MultisiteDomains = array(
    "domain1.com" => array( // domain name is used to map to root page
            "root" => "www.domain1.com", // page name for the root page
            "http404" => 27
        ),
    "domain2.com" => array(
            "root" => "www.domain2.com",
            "http404" => 5332
        )
);

Override for dev environment

$config->MultisiteDomains = array(
    "dev.domain1.com" => array( // domain name is used to map to root page
            "root" => "www.domain1.com", // page name for the root page
            "http404" => 27
        ),
    "dev.domain2.com" => array(
            "root" => "www.domain2.com",
            "http404" => 5332
        )
);

Notes: The page namen for the root page should be carefully taken. It should be as unique as possible, but kept short. it doesn't have to be the domain name 1:1, but can be any string, word or phrase.

For example a name like "event" would be a bad choice, since there might be other pages named "event" in your site, that could lead to problems with the module trying to resolve a requested URL that still contains a domain root name in the URL.

Add urls to httpHosts depending on environment

Live environment

$config->httpHosts = array('domain.com', 'domain2.com');

Dev environment

$config->httpHosts = array('dev.domain.com', 'dev.domain2.com');

Automatic httpHosts setup

$config->MultisiteDomains = […];
$config->httpHosts = array_keys($config->MultisiteDomains);

Domains

Make sure domain2.com points to the same server (A record or CNAME) as domain1.com and so on. And on the server side you have to make sure that domain2.com is pointing to the same directory as domain1.com.

Build the page tree

- Web (PW root page, I call it always "Web" since it isn't the homepage anymore)
   - www.domain1.com (primary site home)
     - Example Page
     - 404 Page
     - Contact Page
   - www.domain2.com (a second site home)
     - 404 Page
   ...

Good to know: some variables

// get current domain
echo $modules->get('Multisite')->domain;
[dev]  'dev.domain1.com'
[live] 'domain1.com'

// get current site root
$siteRoot = $page->rootParent;
echo $siteRoot->name // root page name
[dev]  'www.domain1.com'
[live] 'www.domain1.com'

// use it as navigation starting point
foreach ($siteRoot->children as $child) {
  echo $child->title;
}

TroubleShooting

Wrong page tree structure

- Homepage (main site home)
   - Example Page
   - 404 Page
   - Contact Page
   - www.domain2.com (a second site home)
     - 404 Page
   ...

But this wasn't ever recommended and it can lead to complications.

Domains are missing insite httpHosts

Check that all domains for the specific environment are included inside $config->httpHosts.

DNS Record is not set properly

The DNS Record of all domains must point to the same server.

Domains point to a wrong directory

All domains must point to the same directory.

Multi-language Domains are not working

Make sure the LanguageSupportPageNames module is installed.

Edit the root page in the example above called Web and add language paths there. For example en, de and fr depending on the added languages.

Important

Since the whole concept is all a pretty hack, I found that it comes with some complications that can't be solved in an elegant way. So for example the biggest issue is that you can't crosslink pages via the RTE Link plugin, since it doesn't know about Multisite. So you'll end with wrong URL's when for example you link from a page of one site to a page of another site. If that's an issue it's still possible to copy the ProcessPageEditLink.module and modify the root parent for the page tree select. I'd be glad to help out with an example there.

Again since this module is pretty much a hack, I'm not officially supporting and releasing this module. Use at your own risk. We use it in various projects now and while it works fine with all it's little drawbacks, this version is little more solid.

I would rather like to see if there's a way for a more integrated and supported way in core. But I'm not even sure how this could work out. Ryan may has some ideas or maybe thinks this isn't something PW could support. - Note that there's multisite core support, but it's for different DB's and "site" folders, but that's a different case altogether.

You can’t perform that action at this time.