Page 1 of 1

Multiple domains and sites, ONE CMSMS!

Posted: Sat Jun 14, 2008 6:40 pm
by kermit
Multiple Domains and Sites under ONE CMS Made Simple Installation.

(this is a working draft / work in progress / handle with care)

These instructions (this original post) requires mod_rewrite and Apache web server (Linux); pretty URLs enabled in CMSMS with hierarchy on. HOWEVER MOD_REWRITE IS NOT REQUIRED (see replies to this post).

Requires multiple domains pointing to the same web space (e.g. on cPanel 11 hosts, the additional domains are "Parked Domains"). That web space is assumed to be the root web space for all domains or subdomains being used; use of CMSMS in subdirectories will require some tweaking on your part...

Test environment: Apache 1.3.xx and PHP 5.1.xx running CMS Made Simple 1.3 on Linux 2.6.xx

Here's what I did, in roughly the same order... (Note: as I was writing this, I was changing domains and such on the fly so this could be as 'generic' as possible...)

0. Created a new hosting account (cPanel 11 based server; one of mine) for; parked and (without any redirects) on same account. Web space now answers to three different domains all via http://www.domain.tld/

Note that the domains had previously been configured to point to that server, name servers changed, etc. Registering domains, setting up their name servers, and setting up the account and the domains at a host are all beyond the scope of this little howto.

1. Install CMSMS 1.3 in root of and test. For simplicity in editing/adding test content, I did not install the 'sample content'.

2. Clear CMSMS cache via admin panel.

3. Enable Pretty URLs...

Modify config.php as follows:

Code: Select all

$config['assume_mod_rewrite'] = true;
$config['page_extension'] = '/';
$config['use_hierarchy'] = true;
While I was in there, I also made the following change to the root_url:

Code: Select all

$config['root_url'] = 'http://' . $_SERVER['HTTP_HOST'];
Copy htaccess from ./doc to ./ and rename as .htaccess; modify as follows (complete file shown, except server-specific stuff, such as enabling php5, error doc names, etc):

Code: Select all

# BEGIN CMSMS and Rewrite Rules
RewriteEngine On

# Might be needed esp in a subdirectory
#RewriteBase /

# URL Filtering helps stop some hack attempts
#IF the URI contains a "http:"
RewriteCond %{QUERY_STRING} http\: [OR]
#OR if the URI contains a "["
RewriteCond %{QUERY_STRING} \[ [OR]
#OR if the URI contains a "]"
RewriteCond %{QUERY_STRING} \] [OR]
#OR if the URI contains a "<__script__>"
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
#OR script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
#OR any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2}) 
RewriteRule ^.*$ - [F,L] 

# CMSMS Rewriting
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?page=$1 [QSA]

# second domain and page alias for its domain root
RewriteCond %{HTTP_HOST} domain2\.net [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /domain2site

# third domain and page alias for its domain root
RewriteCond %{HTTP_HOST} domain3\.org [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /domain3site


# END Rewrite rules
The last two parts were added, using the page aliases we'll be using a little later on when we set up content in the back-end for the "other" two domains. These will be the aliases of the "other" domains' "root" or "home" pages.

4. In the back-end, since we did not install the sample content, we've only got a single page, "Home" which will also be the "home page" or domain root for the "first" domain. Modify that so the alias is short but descriptive for the domain. For this howto, we'll just use "one" for the alias of the homepage for

Make a new page, call it and alias it whatever you want, but make "one" the parent of it.

Test the front-end; pretty URLs should be working.

5. Add another new page, alias it what we entered in .htaccess as the page alias for the domain root of the second domain. For this example, we're using "domain2site".

6. Add yet another new page, alias it whatever you want and make "domain2site" its parent page.

At this point, we've got domain1's pages as elements 1 and 1.1, and domain2's pages as elements 2 and 2.1

Now open a new browser window or tab and go striaght to http://www.domain2.tld/ to test. Also check out its child page.

7. Repeat 5 & 6 for the third domain.

ALL DONE. LOOK MA! THREE DOMAINS, ONE CMSMS! All that's left is a little housekeeping...

8. Clean up the menus...

You'll notice in the menus that the "home" of each additional domain has its page alias appended to it. A little messy, but easy to fix. We'll be using a copy of the minimal_menu.tpl here, named MultiSiteMenu, modified as follows (entire changed template shown). See the Smarty comments for what will require a quick edit:

Code: Select all

{if $count > 0}
<ul class="clearfix">
{foreach from=$nodelist item=node}
{if $node->depth > $node->prevdepth}
{repeat string="<ul>" times=$node->depth-$node->prevdepth}
{elseif $node->depth < $node->prevdepth}
{repeat string="</li></ul>" times=$node->prevdepth-$node->depth}
{elseif $node->index > 0}</li>

{* below line should be checking for the aliases of the 'home' pages of the additional domains *}
{if $node->alias eq 'domain2site' or $node->alias eq 'domain3site'}{assign var=utmp value="$root_url/"}
{else}{assign var=utmp value=$node->url}{/if}
{* $utmp replaces $node->url in the menu items below *}

{if $node->current == true}
<li><a href="{$utmp}" class="currentpage"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->parent == true && $node->depth == 1}
<li class="activeparent"> <a href="{$utmp}" class="activeparent"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>

{elseif $node->type == 'sectionheader'}
<li class="sectionheader">{$node->menutext}

{elseif $node->type == 'separator'}
<li style="list-style-type: none;"> <hr class="separator" />

<li><a href="{$utmp}"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>



{repeat string="</li></ul>" times=$node->depth-1}</li>

Then modify the menu call in your site template, so it looks something like this:

Code: Select all

{cms_module module='menumanager' template='MultiSiteMenu'}

9. Clean up and customize the template, CSS and menu items for each "site"...

The entire site template is shown, read the Smarty comments to see what was added and why... (Note: I used a fresh, simple template for this testing, not the default one).

Code: Select all

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "">
<__html xmlns="" xml:lang="en">

{* some initial setup *}
{* strip www. dots and dashes from server host name and assign to a variable for later use *}
{assign var=stmp value=$smarty.server.SERVER_NAME|replace:'www.':''|replace:'.':''|replace:'-':''}
{if $stmp eq 'domain2net'}
   {assign var=ntmp value='This is Domain 2'}{* ntmp is this domains site title *}
   {assign var=mtmp value='2'}{* mtmp is starting element for this domains menu *}
{elseif $stmp eq 'domain3org'}
   {assign var=ntmp value='This is Domain 3'}
   {assign var=mtmp value='3'}
   {assign var=ntmp value='This is Domain 1'}
   {assign var=mtmp value='1'}
{* end setup *}


{* ntmp is our site title from above *}
<title>{title} | {$ntmp}</title>


{* stmp is our mashed up hostname, used to deliver custom stylesheet for each site, named as masheduphostname-styles *}
{* these stylesheets should NOT be associated with the template! *}
{stylesheet name="$stmp-styles"}




<div id="wrap">

<div id="header">

{* ntmp is our site title from above *}

</div><!-- /header -->

<div id="main" class="clearfix">

<div id="side">
<div id="sidemenu">
<h2>Site Menu</h2>

{* mtmp is our starting spot for our menu, only it and its children are shown *}
{cms_module module='menumanager' template='MultiSiteMenu' start_element="$mtmp"}

</div><!-- /sidemenu -->
</div><!-- /side -->
<div id="content">


</div><!-- /content -->

</div><!-- /main -->

<div id="footer">
{global_content name='footer'}
</div><!-- /footer -->

</div><!-- /wrap -->

Note that in this example; I used a single template for all three "sites". Not absolutely necessary but it sped up the testing a bit by keeping everything in one place.

So far this has been just a 'proof of concept' / 'can it be done' experiment..  test before implementation; use at own risk; YMMV; Windows hosts need not apply; etc; etc; etc...

EOF 14JUN08/1220CST DRAFT1  (edit1: some clarifications at the beginning)

(attachment is text file containing this post)

Re: Multiple domains and sites, ONE CMSMS!

Posted: Sat Jun 14, 2008 6:49 pm
by Nullig
Excellent - can't wait to try it.


Re: Multiple domains and sites, ONE CMSMS!

Posted: Sat Jun 14, 2008 9:02 pm
by kermit
to also remove each site's parent alias from the URLs of their children, instead of just the domain roots themselves, so you get...

instead of...

try replacing (in the menu template)...

Code: Select all

{* below line should be checking for the aliases of the 'home' pages of the additional domains *}
{if $node->alias eq 'domain2site' or $node->alias eq 'domain3site'}{assign var=utmp value="$root_url/"}
{else}{assign var=utmp value=$node->url}{/if}
with something like this (using aliases from the original example)...

Code: Select all

{* remove each site's root page alias from their respective 'home pages' and children *}
{assign var=utmp value=$node->url|replace:'/one/':'/'|replace:'/domain2site/':'/'|replace:'/domain3site/':'/'}
or you could use a single regex_replace modifier that does the same thing, if you were so inclined...

Re: Multiple domains and sites, ONE CMSMS!

Posted: Sun Jun 15, 2008 6:19 am
by kermit
you can do this even without mod_rewrite and pretty url's (with just the modified root_url in config.php) so long as you can redirect the 'other' domain roots to their "home page" inside cmsms (perhaps with 301 redirects) and include a little smarty logic in your templates or menus, if necessary, to separate each site's pages and menus.

update: this method is working great on one set of sites i'm working on... although i have skipped the 301 redirects on the 'other' domains' roots to their respective inside pages. instead i've worked both the template and the 'default' page in cmsms to show different content based upon what domain was hit.

EDIT 1.. update.

Re: Multiple domains and sites, ONE CMSMS!

Posted: Sun Jun 15, 2008 7:19 am
by nuno
Okay, i have to say that, i have a multisites system run since Dez 2007, now widt this last fantastic version a ONLY change 3 files and VOILA!

So..., i have multi-domains point to the same install, all is separatly config, temp, uploads, db etc, etc...

If all the modules are not in hardcode everything works well, but sometimes the modules are set up wrong,

include("config.php"); instead include("include.php") put the config strings of uploads and temp instead  manually etc, etc.

Maybe I'll talk to the calguy1000 guru ;) to put the Best Practices in docs or somewhere

BTW: files changes:
fileloc.php, config.php and admin/sitepref.php (to clean the cache)

SINCE 1.4 just fileloc and 1 new config-string so, WOW

Best Regards and good luky

Re: Multiple domains and sites, ONE CMSMS!

Posted: Mon Jun 16, 2008 3:20 am
by JeremyBASS
Hey glad to see the realization of something that was swimming in my head... I like what I see it is working into.... 

This is why I’m so happy to have found CMSms, a community that works together :) have a great one...

Re: Multiple domains and sites, ONE CMSMS!

Posted: Mon Jun 16, 2008 9:40 pm
by JeremyBASS
Hey, there.... I was rereading this and thought that this may need to change
Note that the domains had previously been configured to point to that server, name servers changed, etc. Registering domains, setting up their name servers, and setting up the account and the domains at a host are all beyond the scope of this little how-to.
to include that the domains need to be aliased to root of the cms install to respect the "index.php?page=$1"
It does not seem clear on that fact... though if one was to read the posted stuff from before it'd be clear.... Just a thought...

plus IMHO the use of text also plays more of an important roll...
same with using relative links... ie: uploads/someFolder/someImg.jpg (so one can share parts between sites...)

:) just some thoughts....


Re: Multiple domains and sites, ONE CMSMS!

Posted: Sat Jul 05, 2008 8:25 pm
by kermit
Some notes about a real-world implementation of my "no hack" Multisite mod:

Running Apache on Linux, pretty URLs enabled, but not hierarchy.

Six domains and six separate, but related, sites managed from a single CMSMS 1.3.x installation, and administered by one or two people.

First set up one domain on hosting account, and then added the others as "parked" or "addon" domains to the first. All six domains point to the very same directory; and the server answers as all six, depending upon which one was in the request headers.

ONLY using the config.php mod, no special rewrite rules or redirects.

Using same main template for all sites and pages. Sites all had the same or similar layout before redevelopment with CMSMS, so we just stuck with the same thing; except we did rewrite the html and css from scratch (to clean things up) to achieve the same overall look. Logos, colors, etc. are loaded by specific stylesheets (see below).

Setting up a few Smarty variables above in the template, based upon {$smarty.server.SERVER_NAME}, things like:

* {$ntmp} - actual site name, replaces {sitename}. Used in the description, and here-n-there on a few pages.
* {$mtmp} - start element of each site's menu (using friendly position). Used for menu call. Didn't need to be separated from menu call, but makes it convenient having all the "config" in one spot.
* {$stmp} - a shortened version of the domain name, stripping dots and 'www' out (e.g. leaving 'site1com', etc). Just makes it a little more convenient than using $smarty.server.SERVER_NAME} everywhere. Used for various IF statements in template and a few pages, and also as part of site-specific stylesheet names, as well as image names and/or dirs in places.
* {$ntmp} - default news categories for the site (as would be entered in a news tag). Used on "news" page and in template.
* and a couple others, but those aren't relevant to these notes...

CMSMS "default" page is used by all "sites", and has customized output for each, based upon {$stmp}. This page won't change often and has data pulled from news (using {$ntmp} categories), so it still stays relatively "fresh" provided that news gets added every now-and-then..  something like {global_content name="frontpage-$stmp"} would work here as well... so you could edit each site's "home page" content separately.

Template's menu call uses {$mtmp} to tell MenuManager where each site's menu starts in the overall scheme of things. Each site's menu only shows its own items. Each site's menu starts with a section heading for clarity in the back-end, while {$mtmp} refers to the first child underneath the section headings.

The main template has a screen and print media stylesheet associated with it; the screen one includes the basics (layout, default colors, etc); and an extra, site-specific one (that is not associated with the template) is loaded using something like {stylesheet name="$stmp-screen"} .. on this actual site, though, we're using three separate {static_stylesheet} tags, one for each stylesheet, referenced by name, and in the order we want them in, instead of automatically linking to the stylesheets associated with a template by using a 'bare' tag.

A few pages are shared (such as contact.html, news.html, etc), for those we customize output a bit (again, using the vars above and a couple Smarty IFs). The additional sites using a page have Internal Links to the original (which are listed with the pages of the first, or 'main' site).

There are a couple pages, not shown in menus, that are outside the above menu structure, and just sit at the bottom of the Pages list in the back end. These are linked directly from content or header/footer links, and don't appear in the main site menu.

My Full Page Caching mod is also implemented, and there have been absolutely no issues with it and the Multisite setup. The only other "speed tweak" used is {static_stylesheet} tag...

Overall everything is working just great; the added benefit of having one database and one CMSMS install to back up is a huge plus.

Between the only having 'one' CMSMS install, and eliminating what duplication of 'uploads' files that there was between the sites, the Multisite mod has knocked over 60mb off the storage requirements for the combined sites, and a sizable chunk off every full backup made...  and the Full Page Caching mod has dropped server load to almost nothing (over 90% of page views are at least server-cached), while reducing bandwidth requirements between 30-40% due to browser-caching option.

Re: Multiple domains and sites, ONE CMSMS!

Posted: Fri Sep 19, 2008 7:06 am
by purplerain12

Is multiple domains en websites in one cmsms ONLY possible on a Linux server???


Re: Multiple domains and sites, ONE CMSMS!

Posted: Fri Apr 16, 2010 12:54 pm
by Augustas
Great idea for the multi-domain website! Thank you!
I am using this mod for several of website I maintain.
Most of them are targeted to different countries, therefore I have different domain names (.com,, .ca, etc.) - but the database with design/templates is shared among them and the editor can just login once and edit everything.
Excellent! ;)

Actually, I noticed during the upgrade of new versions of CMSMS, the config.php file is changed, and the line: 

Code: Select all

$config['root_url'] = 'http://' . $_SERVER['HTTP_HOST'];
is changed back to the default:

Code: Select all

$config['root_url'] = '';
So, everytime you upgrade CMSMS, do not forget to modify again the 'root_url' parameter in the config.php

Re: Multiple domains and sites, ONE CMSMS!

Posted: Wed May 12, 2010 11:35 am
by milehigh
Couple notes here on my implementation...below worked for me and gave me a nice clean output. I have Plesk installed on my VPS and the setup was as easy as creating a main domain and then having the other domains aliased under that one to get them to all answer to the same web space. In my case the series of websites all share the exact same template so it was a pretty easy implementation. (basically a bunch of brochure-ware types of sites).

With only one navigation level the only real template change I needed was {menu start_level='2' } so I don't have to modify any menu or template code as I add additional sites.

Code: Select all

$config['assume_mod_rewrite'] = true;
$config['page_extension'] = '.html';
$config['use_hierarchy'] = false;

This saves me about 40 full installations of CMSMS.

Re: Multiple domains and sites, ONE CMSMS!

Posted: Sun Oct 02, 2011 11:07 pm
by jbx1
Regarding step 9 of the original post, with User Defined Tags, one can avoid having to modify the template with ugly {if} conditions.

One can have a user defined tag like: {multi_sitename}
and it would have something like:

Code: Select all

$multi_sitenames = array("" => "The First Domain", "" => "The second domain.");

echo $multi_sitenames[$_SERVER['HTTP_HOST']];

Then in the page templates, one just replaces {sitename} with {multi_sitename} in the <title> tag.

Re: Multiple domains and sites, ONE CMSMS!

Posted: Fri Jul 27, 2012 6:36 pm
by uniqu3
There is MultiDomains Module that you could look at.

Re: Multiple domains and sites, ONE CMSMS!

Posted: Fri Jul 27, 2012 9:26 pm
by Rolf
strangething wrote:Bumping this thread, since I am about to install CMSMS for a client who wants two sites on the same domain. Specifically, it's one site at, and one at
just wondering why bumping a multiple domain thread when you want two sites in one domain... You can do that with one default cmsms install!

Grtz. Rolf