Skip to content
Manoj L edited this page Jun 24, 2021 · 26 revisions

Joomlatools Pages has built-in multi-site support, and allows to add additional sites, which is a great way to use a single Joomla installation to create different micro-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

If you've followed the wiki so far you'll have a /joomlatools-pages directory in your Joomla root.

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

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',
    ],
);

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.]?example.com/shop[*]' => JPATH_ROOT.'/sites/shop',
        '[www.]?example.com[*]'      => JPATH_ROOT.'/sites/site',
        'intranet.example.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]',
    ],
);

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

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' => [
        '[*]/[foo|bar:site]/[**]?' => JPATH_ROOT.'/sites/[:site]',
        '[*]' => JPATH_ROOT . '/sites/default'
    ],
);

In this example there are two sub sites /foo and /bar, along with a default site at /. The /pages directory needs to contain the /pages/foo and/or /pages/bar subdirectory or otherwise pages for each site will not be found.

See also: Using Menus > Creating a Page Menu Item