Skip to content
Johan Janssens edited this page Dec 26, 2019 · 26 revisions

Joomlatools Pages has build in multi-site support, and allows to add additional sites, which is a great way to use a single Joomla installation to create different mirco-sites, landingpages or squeezepages ...

The multisite feature makes it also possible to configure the root Pages directory /joomlatools-pages and point it to a custom location.

Table of contents

Configure default

To re-configure the default site you need to add a configuration-pages.php to your Joomla root, or in case of Joomlatools Platform to /config directory. The configuration will re-define the location of your site:

<?php
return array(
    'sites' => [
        '[*]' => JPATH_ROOT.'/sites/mysite.com',
    ],
);

The default value for the sites config option is [*] => JPATH_ROOT.'/joomlatools-pages'

Adding sites

To add additional sites a route for each site need to be added that resolves the URL to a directory on the file system.

For example to add an example.com and a intranet.example.com site you can use the following routes:

<?php
return array(
    'sites' => [ 
        '[www.]?exmample.com/shop[*]' => JPATH_ROOT.'/sites/shop'
        '[www.]?example.com[*]'       => JPATH_ROOT.'/sites/site',
        'intranet.exmample.com[*]'    => JPATH_ROOT.'/sites/intranet'
    ],
);

Rules

  • Routes are resolved in FIFO order. The first defined route is resolved first, if it cannot be resolved the next route is tried, and so on.
  • Routes are resolved against the HOST + PATH information of the URL. The url schema eg, http:// or https:// should be omitted from the route, otherwise it will not resolve.

Wildcards

  • [*] will match up to the next trailing slash, it ensure that both example.com, example.com/ and example.com/path are matched.
  • [www]? ensures that both www.example.com and example.com are matched.

See also: URLs and Linking > Routes > Wildcards

Note: You can add additional global configuration options to configuration-pages.php. You can still override the options per site in the sites config.php

Vagrant

To add additional sites in our Joomlatools Vagrant Box you need to edit your vhost file at /etc/apache2/sites-available/ and add domain.example.com to the ServerAlias directive then add domain.example.com to your /etc/hosts on your host machine and restart apache2 with box server:restart apache2

Routing sites

Subdomain

Instead of defining a single route per site, it's possible define a route that can route multiple domains. For example to dynamically route all subdomains you can use the following route:

<?php
return array(
    'sites' => [
        '[alpha:site].example.com[*]'   => JPATH_ROOT.'/sites/[:site]',
    ],
);

Subfolder

In case you want to create multiple sites as subfolders you need be careful to make sure that your /pages directory maps to the absolute url path. For example:

<?php
return array(
    'sites' => [
        '[www.]?example.com/[foo|bar:site]/[*]?' => JPATH_ROOT.'/sites/[:site]',
    ],
);

In this example there are two sub sites foo and bar the /pages directory needs to contain the /pages/foo and/or /pages/bar subdirectory or otherwise the pages will not be found.

Wildcards

  • [alpha:site] is a named wildcard that matches the domain. It will only match alphabetic subdomains, and it will not match example.com

See also: URLs and Linking > Routes > Wildcards

Limitations

The multi-site support only works for content and data managed through Joomlatools Pages, and thus stored on the filesystem, it's not capable to create a full database driven multi-site environment in Joomla.

Clone this wiki locally