(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 domain1.com; parked domain2.net and domain3.org (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 domain1.com 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;
Code: Select all
$config['root_url'] = 'http://' . $_SERVER['HTTP_HOST'];
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 CMSMS
# END Rewrite rules
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 domain1.com
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}
</li>
{elseif $node->index > 0}</li>
{/if}
{* 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" />
{else}
<li><a href="{$utmp}"{if $node->target ne ""} target="{$node->target}"{/if}> {$node->menutext} </a>
{/if}
{/foreach}
{repeat string="</li></ul>" times=$node->depth-1}</li>
</ul>
{/if}
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" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<__html xmlns="http://www.w3.org/1999/xhtml" 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'}
{else}
{assign var=ntmp value='This is Domain 1'}
{assign var=mtmp value='1'}
{/if}
{* end setup *}
<head>
{* ntmp is our site title from above *}
<title>{title} | {$ntmp}</title>
{stylesheet}
{* 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"}
{metadata}
</head>
</__body>
<div id="wrap">
<div id="header">
{* ntmp is our site title from above *}
<h1>{$ntmp}</h1>
</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">
<h1>{title}</h1>
{content}
</div><!-- /content -->
</div><!-- /main -->
<div id="footer">
{global_content name='footer'}
</div><!-- /footer -->
</div><!-- /wrap -->
<__body>
</__html>
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)