Hosting Multiple Websites with ModX Revolution

Hosting Multiple Websites with ModX Revolution

This is a neat and tidy way to have multiple TLDs for one installation of MODx.

Within MODx

Go to System > Contexts and Create New for each domain. Name each one using camelCase (e.g. websiteOne) as you can’t use spaces here. This name will be seen in the site tree within the Manager and you will also refer to it later on.

Once finished refresh the manager and they will appear down the left. Right click each one and then Quick Create > Document Here to make a home page. Add a small piece of text on each of the pages so when you test you know it’s reaching the right destination.

Now add content settings by clicking on each heading and add the following:

site_start – the ID of your new context’s homepage.
base_url – Set this value to / as we’re making the root of the URL our base.
http_host – Set this value to domainone.co.uk
site_url – Set this value to http://www.domainone.co.uk/ (Full domain url with a  trailing slash)
error_page – Error page to be set to the id of the context’s home page for now

You can add more here for further customisation. You can create any new ones you like.

File Structure

At the root of the web directory add a directory for each domain and copy index.php and config.core.php from root into each one. There are 2 changes you need to do here (in each directory):

  1. In index.php change $modx->initialize(‘home’); to $modx->initialize(‘websiteOne’);
  2. In config.core.php change define(‘MODX_CORE_PATH’, dirname(__FILE__) . ‘/core/’); to  define(‘MODX_CORE_PATH’, ‘/server/path/to/core/’);

.htaccess

Now you need to tell the server to use these sub directories when each domain name is used. To do create an htaccess file with the following information (update domains and folder names to suit):

RewriteEngine On

RewriteCond %{HTTP_HOST} ^www.domainone.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) folderone/index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www.)?domainone.com$
RewriteRule ^(/)?$ folderone/ [L]

RewriteCond %{HTTP_HOST} ^www.domaintwo.com
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule (.*) foldertwo/index.php?q=$1 [L,QSA]
RewriteCond %{HTTP_HOST} ^(www.)?domaintwo.com$
RewriteRule ^(/)?$ foldertwo/ [L]

php_value memory_limit 64M

 

Kevin Pirnie
22 Years of PC and server maintenance & over 17 years of web development/design experience; you can rest assured that I take every measure possible to ensure your computers are running to their peak potentials. I treat them as if they were mine, and I am quite a stickler about keeping my machines up to date and optimized to run as well as they can.