Giter Site home page Giter Site logo

multisite's Introduction

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.

multisite's People

Contributors

apeisa avatar arjenblokzijl avatar lostkobrakai avatar somatonic avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

multisite's Issues

Warnings and Notices on install

Hey soma - I just installed your fork on a new site and received these during install. All gone once the sites field was populated and submitted.

Warning: strpos(): Empty needle in /Users/ajones/Sites/pwnew/site/modules/Multisite/Multisite.module on line 138

Notice: Undefined index: subdomains in /Users/ajones/Sites/pwnew/site/modules/Multisite/Multisite.module on line 219

parseLinks() does not account for https

Should the parseLinks() method use the protocol set by config->https rather than hardcoding http?

In our project we had a search form submitting to a page of a different domain on the same site (using $pages->get(id)->httpUrl, and when we switched to ssl the browser complained about the site not being fully secure.

Processwire 3.X support

Hi, does this module work in Processwire 3.x?
It seems that doesn't. But I am quite new to Processwire so… who knows :-)
If not, any plans to add support it later?
Thanks

Two issues

I'm getting a

Notice: Undefined index: it in /site/modules/Multisite/Multisite.module on line 68

all the time. Also any request to a page of my subdomain homepage(ie subdomain.de/subpage) gets redirected to the homepage (subdomain.de) ... I can't reallly figure it out but I saw this fork is rather active so I figured I might as well ask :)
Thanks,
thomas

infinite redirect loop

I have successfully used this plugin on several projects. This time it’s not working, maybe you have an idea!

After your Module has correctly updated $_GET['it'] to the correct path, ProcessWire does not simply fetch and show the content from this path, but instead it does a redirect to this location. Then your Module runs again and does – of course – a redirect to the original URL, resulting in an endlos redirect loop like this:

bnd.nicht.live > bnd.nicht.live/bnd.de > bnd.nicht.live > bnd.nicht.live/bnd.de

How can I prevent ProcessWire from physically redirect to the manipulated $_GET['it']?

dev version: View links does not work with other home path than "/"

In the dev version: another home path than "/" leads to a "404 not found" when clicking "view" in page tree or in page detail.

My Setup:
pw is installed in "/pw_test/"
normal page works.

Page Tree:

- Web
   - pw1
     - Pages
   - pw2
     - Pages

Multidomain setup:

$config->MultisiteDomains = array(
  "pw1.domain.com" => array( 
    "root" => "pw1",
    "http404" => PAGEID
  ),
  "pw2.domain.com" => array(
    "root" => "pw2",
    "http404" => PAGEID
  )
);

$config->httpHosts = array('localhost', 'pw1.domain.com', 'pw2.domain.com');

in my /etc/hosts pw1.domain.com and pw2.domain.com leads to localhost

The view link leads to "http://local1.domain.com/pw_testhttp://local1.domain.com/en/"
The URL http://local1.domain.com/pw_test/en works as excepted though.

In the same setup with home path "/" the "view" links work.

insert cross-domain internal page link into WYSIWYG

My client has 4 domains in use and sometimes wants to set a cross-link from one domains’ page to another domain’s page. When he uses the internal page picker (see screenshot), the address is generated as relative, starting with "/" instead of the domain of the linked page.

Any thoughts how we might fix this problem, other than writing a TextFormattor that detects any internal links, checks their domains and adds that domain? This sounds not very elegant to me.

bildschirmfoto_2017-01-09_um_09 42 32-1

Modul chooses wrong domain (when multiple domains have the same root)

When you have multiple domains in your config, sharing the same root e.g.

you have config for local dev and online env

$config->MultisiteDomains = array(
    "domain1.com" => array(
            "root" => "root_domain1.com",
            "http404" => 27
        ),
    "domain1.local" => array(
            "root" => "root_domain1.com",
            "http404" => 27
        )
);

The modul always redirects links to the first domain, where the root-key matches.

expected behavoir (on domain domain1.local)

  • it should rewrite links to domain1.local

current behavoir

  • modul rewrites links to domain1.com

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.