-
Notifications
You must be signed in to change notification settings - Fork 9
Multisite
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.
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',
],
);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'
],
);- 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://orhttps://should be omitted from the route, otherwise it will not resolve.
-
[*]will match up to the next trailing slash, it ensure that bothexample.com,example.com/andexample.com/pathare matched. -
[www]?ensures that bothwww.example.comandexample.comare 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
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
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]',
],
);-
[alpha:site]is a named wildcard that matches the domain. It will only match alphabetic subdomains, and it will not matchexample.com
See also: URLs and Linking > Routes > Wildcards
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
Got a question or need help? We have a forum on Github Discussions where you can get in touch with us.