easy subdomains with one install (with multiple domains updated)

Do something cool with CMS? Show us ...
This board is for 'Answers', and the discussion of answers... Not for questions.
JeremyBASS

easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

If you have read thru the forum you may have saw that I works heavily on having cmsms handle multiple domains... I thought I'd share this since I saw another user seemed to need it.  That and I have not found it in search the forum.  So down to it.. This work pretty much the same as what I did to get handle 5 domains in one install. 

first in your config.php

trun this (~line 77)
$config['root_url'] = 'http://www.domain.tdl';

in to

$config['root_url'] = 'http://' . $_SERVER['SERVER_NAME'];

then

in the

.htaccess put

Current 03-27-09

# example.com to www.example.com  force -- to insure URL integrity
RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]

RewriteCond %{HTTP_HOST} !^www\.example.tdl
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ([^.]+)\.example.tdl
RewriteRule ^(.*)$ %1

now this is used in conjunction with pretty URL's... and you need to point everything to the root, your working under the fact the CMSMS can be thought of as a vitural file system... so we treat it is such

then you just make top level pages so if you have

http://blog.domain.com/

then the page alias would be

blogs

Now you'll use the same tricks as before, but now target blog for the support parts, ie :menu

Hope this helps

Cheers
jeremyBass
Last edited by JeremyBASS on Sat Mar 28, 2009 3:52 am, edited 1 time in total.
JeremyBASS

Re: easy subdomains with one install

Post by JeremyBASS »

Here is the GCB "_domainRealization" that you should be using for best success.

Code: Select all

{assign var=domain value="corbensproducts"}
{assign var=root value=$smarty.server.SERVER_NAME}
{assign var=tdl value=$root|replace:"`$domain`":""|regex_replace:'/www|blog/':''|replace:".":""}
{assign var=subD value=$root|replace:"`$domain`":""|replace:"`$tdl`":""|replace:".":""}
{assign var=PageEx value=".html"}

{* you can delete from here down and use what you want *}
The root is {$root}<br/>


{if isset($tdl)}
the tdl is {$tdl}<br/>
{/if}
{if isset($subD)}
the sub domain is {$subD}<br/>
{/if}

all of domain {$domain}
Just change the main domain from "Yourdomain" to your domain, and if you have more then www and blog as a subdomain just add |whatever to the list regex_replace:'/www|blog/' like so

regex_replace:'/www|blog|whatever/'

Also if you use any of my tricks from before you should switch the old domainRealization to this... it's much cleaner general and to the point.


cheers
jeremyBass
Last edited by JeremyBASS on Sun Feb 15, 2009 4:24 am, edited 1 time in total.
JeremyBASS

Re: easy subdomains with one install

Post by JeremyBASS »

so here is the setup I have working

GCB "_domainRealization"

Code: Select all

{assign var=MAINdomain value="corbensproducts"}
{assign var=CurrentRoot value=$smarty.server.SERVER_NAME}
{assign var=CurrentTDL value=$CurrentRoot|replace:"`$MAINdomain`":""|regex_replace:'/www|blog|forum|computers|help|webdesign|hosting|news/':''|replace:".":""}
{assign var=CurrentSubD value=$CurrentRoot|replace:"`$MAINdomain`":""|replace:"`$CurrentTDL`":""|replace:".":""}
{assign var=PageEx value=".html"}{* your page extension*}
{assign var=SubDtdl value="com"}{*your default tdl*}
{assign var=MAINsub value="www"}{*your default subdomain*}

{*the tld array for you site*}
{array var="tdls" value="com"}
{array var="tdls" value="net"}
{array var="tdls" value="biz"}
{array var="tdls" value="info"}
{array var="tdls" value="org"}

{* subdomain arry for your site*}
{array var="subD" value="computers"}
{array var="subD" value="webdesign"}
{array var="subD" value="hosting"}
{array var="subD" value="websales"}
{array var="subD" value="forum"}
{array var="subD" value="news"}
{array var="subD" value="blog"}
{array var="subD" value="help"}
added

http://smarty.incutio.com/?page=array
to the smarty plugins folder


and here is the menu,

Code: Select all

{strip}{if $count > 0}
<div id="menuwrapper" >
<ul id="primary-nav">



{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}

<li class="{if $node->parent == true or ($node->current == true and $node->haschildren == true)}menuactive menuparent{elseif $node->current == true}menuactive{elseif $node->haschildren == true}menuparent{/if}" >

{assign var=nodeTDLIS value=$node->url|replace:"http://":""|replace:"$CurrentSubD.$MAINdomain.$CurrentTDL/":""|replace:"$PageEx":""|regex_replace:"/\/.+$/":""}
NODE DOMAIN IS:{$nodeTDLIS}
            {foreach from=$tdls item=tdlsI}
                {if $nodeTDLIS eq $tdlsI} 
                	{assign var=utmp value=$node->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTDL":"$MAINsub.$MAINdomain.$nodeTDLIS"|replace:".$tdlsI/$tdlsI$PageEx":".$tdlsI"|replace:".$tdlsI/$tdlsI":".$tdlsI"|replace:".$CurrentTDL/$tdlsI":".$tdlsI"}
                {elseif $nodeTDLIS eq ''} 
                	{assign var=utmp value=$node->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTDL":"$MAINsub.$MAINdomain.$SubDtdl"|regex_replace:"/`$MAINdomain`.+$/":"$MAINdomain.$SubDtdl"}
                {/if}
            {/foreach}
            {foreach from=$subD item=subDI}
                {if $nodeTDLIS eq $subDI} 
                	{assign var=utmp value=$node->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTDL/$subDI$PageEx":"$subDI.$MAINdomain.$SubDtdl"}
                {/if}
            {/foreach}
 <a href="{$utmp}" {if $node->accesskey != ''}accesskey="{$node->accesskey}" {/if}{if $node->tabindex != ''}tabindex="{$node->tabindex}" {/if}{if $node->titleattribute != ''}title="{$node->titleattribute}"{/if}{if $node->target neq ""} target="{$node->target}"{/if}><dfn>{$node->hierarchy}: </dfn>{$node->menutext}</a>

 

{/foreach}


	{repeat string="</li></ul>" times=$node->depth-1}		</li>
	</ul>
<div class="clearb"></div>
</div>
{/if}{/strip}

this is both the mulity domain and subdomain setup.... just edit GCB "_domainRealization"  for your needs...

hope this helps

cheers
jeremyBass
Last edited by JeremyBASS on Sun Feb 15, 2009 10:21 pm, edited 1 time in total.
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

just refining what I have.. to date I believe this is better..

Code: Select all

{assign var=nodeTDLIS value=$node->url|replace:"http://":""|replace:"$CurrentSubD.$MAINdomain.$CurrentTDL/":""|replace:"$PageEx":""|regex_replace:"/\/.+$/":""}
            {foreach from=$tdls item=tdlsI}
                {if $nodeTDLIS eq $tdlsI} 
                               {assign var=utmp value=$node->url|replace:"$CurrentSubD":"$MAINsub"|replace:"$MAINsub.$MAINdomain.$CurrentTDL":"$MAINsub.$MAINdomain.$nodeTDLIS"|replace:".$tdlsI/$tdlsI$PageEx":".$tdlsI"|replace:".$tdlsI/$tdlsI":".$tdlsI"|replace:".$CurrentTDL/$tdlsI":".$tdlsI"}
                {elseif $nodeTDLIS eq ''} 
                			{assign var=utmp value=$node->url|replace:"$CurrentSubD":"$MAINsub"|replace:"$MAINsub.$MAINdomain.$CurrentTDL":"$MAINsub.$MAINdomain.$SubDtdl"|regex_replace:"/`$MAINdomain`.+$/":"$MAINdomain.$SubDtdl"}
                {/if}
            {/foreach}
            {foreach from=$subD item=subDI}
                {if $nodeTDLIS eq $subDI} 
                				{assign var=utmp value=$node->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTDL":"$nodeTDLIS.$MAINdomain.$SubDtdl"|replace:".$SubDtdl/$subDI$PageEx":".$SubDtdl"|replace:".$SubDtdl/$nodeTDLIS":".$SubDtdl"}
               {/if}
            {/foreach}
little more flexible, and should account for any url configuration (still in pretty urls only).

Cheers
jeremyBass
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

Ok... I keep refining... basicly I see that this can become a mod it's self... like superDomains...


So I figured that It'd be handy to have a way to intergate google analytics... so this is what I did.

switch the array php for this one...

http://www.phpinsider.com/smarty-forum/ ... hp?t=14132

which made it easy to  an associate array and then tied the key code for analytics to each tld and subdomain.

looks like this..

GCB _domainRealization
//////////////EDIT/////////////////
I add a . in
|replace:"`$CurrentTLD`":""

in order to keep from geting computers when the tld is com from truning into something other then what in needed to be... so

$CurrentSubD would not end up "comwww"

So that's making it

|replace:".`$CurrentTLD`":""



Code: Select all

{strip}

{assign var=MAINdomain value="corbensproducts"}
{assign var=CurrentRoot value=$smarty.server.SERVER_NAME}
{assign var=CurrentTLD value=$CurrentRoot|replace:"`$MAINdomain`":""|regex_replace:'/www|blog|forum|computers|help|webdesign|hosting|news|websales|myhome/':''|replace:".":""}
{assign var=CurrentSubD value=$CurrentRoot|replace:"`$MAINdomain`":""|replace:".`$CurrentTLD`":""|replace:".":""}
{assign var=PageEx value=".html"}
{assign var=SubDtdl value="com"}
{assign var=MAINsub value="www"}


{array vars="array('com'=>'UAXX6332702XX1','net' =>'UAXX6332702XX2','biz'=>'UAXX6332702XX3','org'=>'UAXX6332702XX4','info'=>'UAXX6332702XX5')" assign="TLDs"} 

{array vars="array('computers'=>' ','webdesign' =>'' ,'hosting'=>' ','websales'=>' ','forum'=>' ','news'=>' ','blog'=>' ','help'=>' ','myhome'=>' ')" assign="subD"} 

{/strip}


made a new GCB _GoogleSwitch

Code: Select all

{assign var=UA_Google value=''} 
{foreach from=$TLDs key=tdlsI item=tdlsIv}
                {if $CurrentTLD eq $tdlsI} 
                               {assign var=UAGoogle value=$tdlsIv}
                {/if}
  {/foreach}



{literal}<__script__ type="text/javascript">
var gaJsHost = (("https:" == document.location.protocol) ? "https://ssl." : "http://www.");
document.write(unescape("%3Cscript src='" + gaJsHost + "google-analytics.com/ga.js' type='text/javascript'%3E%3C/script%3E"));
</__script>
<__script__ type="text/javascript">
var pageTracker = _gat._getTracker("{/literal}{$UAGoogle|replace:"XX":"-"}{literal}");
pageTracker._initData();
pageTracker._trackPageview();
</__script>{/literal}
but inorder to keep the menu working I made this switch...
//////////////EDIT/////////////////
in order to account for "folders" (think virtual folders here) that do not match the subdomains or tlds I push it over to the default subdomain and tld


Code: Select all

{if $count > 0}
<div id="menuwrapper" >
<ul id="primary-nav">


{foreach from=$nodelist item=node}
{assign var=tldmatch  value=false}
{assign var=Submatch  value=false}
{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}

<li class="{if $node->parent == true or ($node->current == true and $node->haschildren == true)}menuactive menuparent{elseif $node->current == true}menuactive{elseif $node->haschildren == true}menuparent{/if}" >

{assign var=nodeTDLIS value=$node->url|replace:"http://":""|replace:"$CurrentSubD.$MAINdomain.$CurrentTLD/":""|replace:"$PageEx":""|regex_replace:"/\/.+$/":""}
            {foreach from=$TLDs key=tdlsI item=tdlsIv}
                {if $nodeTDLIS eq $tdlsI} 
                               {assign var=utmp value=$node->url|replace:"$CurrentSubD":"$MAINsub"|replace:"$MAINsub.$MAINdomain.$CurrentTLD":"$MAINsub.$MAINdomain.$nodeTDLIS"|replace:".$tdlsI/$tdlsI$PageEx":".$tdlsI"|replace:".$tdlsI/$tdlsI":".$tdlsI"|replace:".$CurrentTLD/$tdlsI":".$tdlsI"}
                               {assign var=tldmatch  value="true"}
                {elseif $nodeTDLIS eq ''} 
                	{assign var=utmp value=$node->url|replace:"$CurrentSubD":"$MAINsub"|replace:"$MAINsub.$MAINdomain.$CurrentTLD":"$MAINsub.$MAINdomain.$SubDtdl"|regex_replace:"/`$MAINdomain`.+$/":"$MAINdomain.$SubDtdl"}
                    {assign var=tldmatch  value="true"}
                {/if}
            {/foreach}
            {foreach from=$subD key=subDI item=subDIv}
                {if $nodeTDLIS eq $subDI} 
                	{assign var=utmp value=$node->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTLD":"$nodeTDLIS.$MAINdomain.$SubDtdl"|replace:".$SubDtdl/$subDI$PageEx":".$SubDtdl"|replace:".$SubDtdl/$nodeTDLIS":".$SubDtdl"}
                    {assign var=Submatch  value="true"}
                    {elseif ($Submatch neq "true") and ($tldmatch neq "true")} 
                    
                    {assign var=utmp value=$node->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTLD":"$MAINsub.$MAINdomain.$SubDtdl"}
               {/if}
            {/foreach}
 <a href="{$utmp}" {if $node->accesskey != ''}accesskey="{$node->accesskey}" {/if}{if $node->tabindex != ''}tabindex="{$node->tabindex}" {/if}{if $node->titleattribute != ''}title="{$node->titleattribute}"{/if}{if $node->target neq ""} target="{$node->target}"{/if}><dfn>{$node->hierarchy}: </dfn>{$node->menutext}</a>

 

{/foreach}


	{repeat string="</li></ul>" times=$node->depth-1}		</li>
	</ul>
<div class="clearb"></div>
</div>
{/if}
if I can ever get the time I'll make this in to a mod you can just intsall and add the values, so you don't have to have the array php script and it's able to be changed on the fly from the admin sde...


hope this helps

cheers
jeremyBass
Last edited by JeremyBASS on Sun Feb 22, 2009 9:33 pm, edited 1 time in total.
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

Ok... here is a big handy update... if you want a use to login and move from subdomain to subdomain you need make one small edit to the include.php file.  Now this is hack here, but hopefully I or someone can get it set so that we can set this in the config.php and include this in the core.

So the trick... at line ~39 insert

@ini_set('session.cookie_domain', '.corbensproducts.com');

were .corbensproducts.com is the base of your site... the main domain.

it needs to be right above

    @session_start();

like this

Code: Select all

if(!@session_id())
{
    #Trans SID sucks also...
    @ini_set('url_rewriter.tags', '');
    @ini_set('session.use_trans_sid', 0);
	//@ini_set('session.cookie_domain', $config['session_domain']);
	@ini_set('session.cookie_domain', '.corbensproducts.com');
    @session_start();
	
    if( isset($CMS_ADMIN_PAGE) )
Now you can safely pass the session from subdomain to subdomain...


cheers
jeremyBass
brocki
New Member
New Member
Posts: 3
Joined: Wed Jan 28, 2009 7:37 pm

Re: easy subdomains with one install (with multiple domains updated)

Post by brocki »

Okay, this is of interest to me since I'm trying to set up a few subdomains on one install of cmsms. So, for someone really just learning the basics of how PHP works, how do I put this all together? I'm having an "explain it to me like I'm six" moment. I'm running 1.5.3.

I totally get the first post. I can do that, but after that I'm dead lost. Should I implement all these tweaks in order, start with the last one? I'm lost at DomainRealization. I feel like this is something I could implement if I just knew where exactly to put what.

As far as what I'm trying to do:

-I want the "standard" domain to work as normal, with public access.

-subdomain1 (members.site.com) to have members-only access. I've been having trouble with frontendusers, so I currently have the entire subdomain itself secured through my cpanel backend (assuming that's .htaccess?) I intend to

-subdomain 2 (project.site.com) with a mix of public and private pages. The private members of this site would be totally different from the members of the first. Since I am dealing with all these different usergroups, I know I probably need to sort out the problems I'm having with FEU, but in a pinch I guess I could also use the cpanel controls?

My host stores subdomains as folders within my root, but I realize they are only accessible from sub.site.com, not site.com/sub, even though the folder is stored that way.
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

@brocki ... I think the easiest way to think about this is that CMSMS pages can also be treated as folders... so since your subdomain folder would be in your root named subdomain1 then you would create a page with the page alias as subdomain1 as well.  Then you add the htaccess above.  Also as stated above if you don't have pretty urls turned on this will not work right with the code I provided.

so step:
1.) is point all dns alias to the root of your site
2.) trun on and make the changes to your config.php file as stated above.
3.) add the stated .htaccess code from above

That is the first layer to this... then you want to configure CMSMS to handle the subdomains.

4.) add the array function for smartys to the site (I was told that it may be in the core later)
http://www.phpinsider.com/smarty-forum/ ... hp?t=14132
5.) add the GCB    _domainRealization as stated above and adjust the values as needed... (most are from the config and labeling your subdomains... you put it be for everything in your templates.  then you can use the code everywhere in all mods)
6.) add the menu template (it's cut and paste minus styling)

that is layer two.

7.) 'UAXX6332702XX1' that is the Google code for Google analytics... so if you use it then put it in if no you can just use ''...
(tip: set the domain for Google as domain.tld)
8.) ad GCB _GoogleSwitch as stated above.
9.) make the change to inculdes.php as stated above and you will have FEU holding a login thru all subdomains. 
(now that is the only core change needed for this to work... but until the core developers can make the suggested change I asked for you will have to make that change on an update.)


All those sets will do all that you ask for, and more.

There are still things that need to be worked out so I can just make a mod for this but... A mod will come for this as the admin side could handle all this... and My2Cents would be to say that this trick need to be n the core as then people will stop installing more then one copy on there domain to do things like this...


Hope that helps...

cheers
jeremyBass
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

This is the end result of what I have laid out so far...

http://forum.corbensproducts.com/


There is one thing that seems to be an issue... com and computer get mixed up... that is what I'm working on fixing before I aim to do a mod. 

Cheers
jeremyBass
brocki
New Member
New Member
Posts: 3
Joined: Wed Jan 28, 2009 7:37 pm

Re: easy subdomains with one install (with multiple domains updated)

Post by brocki »

;D thanks so much... I'll work on this tonight and see if I can get it going.
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

Here is the SitemapMS example file...

Code: Select all

{* sitemap template *}
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.google.com/schemas/sitemap/0.84"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.google.com/schemas/sitemap/0.84
	http://www.google.com/schemas/sitemap/0.84/sitemap.xsd">{strip}
	{global_content name='_domainRealization'}
{foreach from=$output item='page'}
{assign var=nodeTDLIS value=$page->url|replace:"http://":""|replace:"$CurrentSubD.$MAINdomain.$CurrentTLD/":""|replace:"$PageEx":""|regex_replace:"/\/.+$/":""}
            {foreach from=$TLDs key=tdlsI item=tdlsIv}
                {if $nodeTDLIS eq $tdlsI} 
                               {assign var=utmp value=$page->url|replace:"$CurrentSubD":"$MAINsub"|replace:"$MAINsub.$MAINdomain.$CurrentTLD":"$MAINsub.$MAINdomain.$nodeTDLIS"|replace:".$tdlsI/$tdlsI$PageEx":".$tdlsI"|replace:".$tdlsI/$tdlsI":".$tdlsI"|replace:".$CurrentTLD/$tdlsI":".$tdlsI"}
                               {assign var=tldmatch  value="true"}
                {elseif $nodeTDLIS eq ''} 
                	{assign var=utmp value=$page->url|replace:"$CurrentSubD":"$MAINsub"|replace:"$MAINsub.$MAINdomain.$CurrentTLD":"$MAINsub.$MAINdomain.$SubDtdl"|regex_replace:"/`$MAINdomain`.+$/":"$MAINdomain.$SubDtdl"}
                    {assign var=tldmatch  value="true"}
                {/if}
            {/foreach}
            {foreach from=$subD key=subDI item=subDIv}
                {if $nodeTDLIS eq $subDI} 
                	{assign var=utmp value=$page->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTLD":"$nodeTDLIS.$MAINdomain.$SubDtdl"|replace:".$SubDtdl/$subDI$PageEx":".$SubDtdl"|replace:".$SubDtdl/$nodeTDLIS":".$SubDtdl"}
                    {assign var=Submatch  value="true"}
                    {elseif ($Submatch neq "true") and ($tldmatch neq "true")} 
                    
                    {assign var=utmp value=$page->url|replace:"$CurrentSubD.$MAINdomain.$CurrentTLD":"$MAINsub.$MAINdomain.$SubDtdl"}
               {/if}
            {/foreach}
{/strip}<url>
  <loc>{$utmp}</loc>
  <lastmod>{$page->date|date_format:"%Y-%m-%d"}</lastmod>
  <priority>{$page->priority}</priority>
  <changefreq>{$page->frequency}</changefreq>

</url>
{/foreach}
{capture assign='junk'}{news category="Press Releases" number='1000'}{/capture}
{foreach from=$items item=entry}
{assign var=utmpNEWS value=$entry->moreurl|replace:'//':'/109/'|replace:'http:/109':'http:/'|replace:'www.':'news.'}
<url>
  <loc>{$utmpNEWS}</loc>

{if $entry->formatpostdate}
  <lastmod>{$entry->formatpostdate|date_format:"%Y-%m-%d"}</lastmod>
{/if}
<priority>{$page->priority}</priority>
  <changefreq>{$page->frequency}</changefreq>
</url>
{/foreach}
{capture assign='junk'}{Blogs numentries="10000"}{/capture}
{foreach from=$items item=entry}
{assign var=utmpBLOGS value=$entry->entryurl|replace:'//':'/106/'|replace:'http:/106':'http:/'|replace:'www.':'blog.'}
<url>
  <loc>{$utmpBLOGS}</loc>
  <lastmod>{$entry->time|date_format:"%Y-%m-%d"}</lastmod>
<priority>{$page->priority}</priority>
  <changefreq>{$page->frequency}</changefreq>
</url>
{/foreach}
</urlset>

it has a news example and blog example as well... (106 and 109 are the content_id for the respective items)

cheers
jeremyBass
Last edited by JeremyBASS on Sun Mar 22, 2009 2:36 am, edited 1 time in total.
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

mmm.. I'll come back to this... hehe  ::)
Last edited by JeremyBASS on Sat Mar 28, 2009 3:53 am, edited 1 time in total.
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

So there is an need to force the www inorder to keep this working right all the time...

Here it is...

# example.com to www.example.com&nbsp; force -- to insure URL integrity
RewriteCond %{HTTP_HOST} ^(example\.com)$ [NC]
RewriteRule ^(.*)$ http://www.%1/$1 [R=301,L]


RewriteCond %{HTTP_HOST} !^www\.example.tdl
RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{HTTP_HOST} ([^.]+)\.example.tdl
RewriteRule ^(.*)$ %1


Cheers
jeremyBass
Dan Collins

Re: easy subdomains with one install (with multiple domains updated)

Post by Dan Collins »

Hi Jeremy I am trying to follow your instructions.

I am having no luck at all, please could you offer your wisdom to the matter.

I have installed cms made simple on www.dan-test1.co.uk and mapped www.dan-test2.co.uk to this domain.

I Have edited the content of config.php to look like the following...

Code: Select all

#-------------
#Path Settings
#-------------

#Document root as seen from the webserver.  No slash at the end
#If page is requested with https use https as root url
#e.g. http://blah.com
$config['root_url'] = 'http://' . $_SERVER['HTTP_HOST'];
if(isset($_SERVER['HTTPS']) && $_SERVER['HTTPS']=='on')
{
$config['root_url'] = str_replace('http','https',$config['root_url']);
}

#Path to document root. This should be the directory this file is in.
#e.g. /var/www/localhost
$config['root_path'] = '/home/sites/dan-test1.co.uk/public_html';

#Name of the admin directory
$config['admin_dir'] = 'admin';

#Where do previews get stored temporarily?  It defaults to tmp/cache.
$config['previews_path'] = '/home/sites/dan-test1.co.uk/public_html/tmp/cache';

#Where are uploaded files put?  This defaults to uploads.
$config['uploads_path'] = '/home/sites/dan-test1.co.uk/public_html/uploads';

#Where is the url to this uploads directory?
$config['uploads_url'] = $config['root_url'] . '/uploads';


#---------------
#Upload Settings
#---------------

#Maxium upload size (in bytes)?
$config['max_upload_size'] = 2000000;

#Permissions for uploaded files.  This only really needs changing if your
#host has a weird permissions scheme.
$config['default_upload_permission'] = '664';

#------------------
#Usability Settings
#------------------

#Allow smarty {php} tags?  These could be dangerous if you don't trust your users.
$config['use_smarty_php_tags'] = false;

#Automatically assign alias based on page title?
$config['auto_alias_content'] = true;

#------------
#URL Settings
#------------


#Show mod_rewrite URLs in the menu? You must enable 'use_hierarchy' for this to work for modules
$config['assume_mod_rewrite'] = true;

#Extension to use if you're using mod_rewrite for pretty URLs.
$config['page_extension'] = '/';


and my .htaccess to look like this...

Code: Select all

# Attempt to override some php settings, these settings may be helpful on some hosts if your
# default configuration does not meet CMS's minimum requirements, and your host
# has given your account appropriate permissions
#php_value upload_max_filesize "10M"
#php_value session_save_path "tmp/cache"

#php_flag magic_quotes_gpc Off
#php_flag register_globals Off
#php_flag session.use_trans_sid Off

# (this is important, so uncomment if your host permit)
#Options -Indexes
#ServerSignature Off
#
Options +FollowSymLinks
#
<IfModule mod_rewrite.c>
# 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} dan-test2\.co.uk [NC]
RewriteCond %{REQUEST_URI} ^/$
RewriteRule .* /dan-test2



# END CMSMS

# END Rewrite rules


</IfModule>



I have then created the correct pages and aliases as suggested in [url=http://"http://forum.cmsmadesimple.org/index.php/topic,22890.0.html"]this post[/url].

Image

The url rewriting doesnt seem to be working, I think this is my main problem.

If i go to www.dan-test1.co.uk and click on any of the links in the left navigation I get 404 errors.

Can you see something that I have done wrong?, maybe you can provide some suggestion/solutions.


Thanks in advance

Dan
Attachments
CMSpages.jpg
JeremyBASS

Re: easy subdomains with one install (with multiple domains updated)

Post by JeremyBASS »

mmm... I think your wanting the muilty domain solution.. this is subdomain ... I think I see why  thou..

read this first... kramit wrote up on my original post which is in here some were... deals more with the
www.domain1.com
www.domain2.com

set up


http://forum.cmsmadesimple.org/index.ph ... 890.0.html

also I expanded on my original work many times and there is lots in this area about this type of treatment... hope this helps some

cheers
jeremyBass
Post Reply

Return to “Tips and Tricks”