On 2/13/06, Theo Galanakis <[EMAIL PROTECTED]> wrote:
When a user enters either subsite1 or subsite2, cf code looks at the
cgi.http_host variable to determine which subdomain the user is looking
at, this changes the navigation structure to another navigation point on
the root structure. E.g.


I'm not sure I understand correctly what you're trying to do, so apologies if I've missed the point.

You want two or more separate sites, running from the one FarCry app (ie, sharing the tree and database), yes?

Here's an example of running multiple domains/separate sites using one FarCry app. This may or may not be the best way to do it, it's a suggested way.

1. THE SITE TREE

Subsite1 accessible via its domain, as well as the "master" domain; Subsite2 only accessible via its domain:

Root
- Home (navalias:home) - nLevel:1
-- dmCSS
-- dmHTML displayHandler=displayPageStandard
-- node
-- Subsite 1 (navalias:subsite1) - nLevel:2
--- dmCSS for subsite 1
--- dmHTML displayHandler=displayPageSubsite1
--- node
- Subsite 2 (navalias:subsite2) - nLevel:1
-- dmCSS for subsite 2
-- dmHTML displayHandler=displayPageSubsite2
-- node


2. THE WEB SERVER

Now, the tricky part here is how to process the multiple domains. You've got two CGI variables at your disposal, SERVER_NAME and HTTP_HOST

The problem with HTTP_HOST is that it's passed in via the client (e.g. visitor's web browser) and there's always a chance it won't be set or necessarily what you expect.

SERVER_HOST on the other hand is set by the server itself. But, depending on how you set up your virtual hosts it may not give you what you need.

An Apache example:

<VirtualHost *:80>
    DocumentRoot /Library/WebServer/applications/farcry_app/www
    ServerName mainsite.com
    ServerAlias www.mainsite.com
    ServerAlias subsite1.com
    ServerAlias www.subsite1.com
    Alias /farcry/ /Library/WebServer/farcry/p230/farcry_core/admin/
    Alias /farcry  /Library/WebServer/farcry/p230/farcry_core/admin
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot /Library/WebServer/applications/farcry_app/www
    ServerName subsite2.dev
    ServerAlias www.subsite2.com
    Alias /farcry/ /Library/WebServer/farcry/p230/farcry_core/admin/
    Alias /farcry  /Library/WebServer/farcry/p230/farcry_core/admin
</VirtualHost>


Our first virtual host is for our mainsite.com and also has an alias for subsite1.com

The visitor requests www.subsite1.com. Their browser provides the correct HTTP_HOST header
cgi.HTTP_HOST = www.subsite1.com
cgi.SERVER_NAME = mainsite.com

SERVER_NAME doesn't give us what we need because subsite1.com is an alias of mainsite.com

The second virtual host makes sure the SERVER_NAME is set as we need
cgi.HTTP_HOST = www.subsite2.com
cgi.SERVER_NAME = subsite2.com


So, for each subsite you want to add, you'll need to set up a virtual host.  (NOTE: tested on Apache 1.3, jump in if there's a better way of doing this.)

How will this affect you? If you have this level of control over your server, not at all. But if you're hosting on a shared server, you might need to cosy up to your hosts.


3. THE FARCRY APPLICATION

OK, so our tree is set up as needed and the server can tell us which site to serve. Since FarCry will serve the requested page based on objectID, we only need to worry about which "home page" gets served.

Add to the bottom of your Application.cfm,

<cfscript> // multiple domain handling

if((not isDefined("url.objectid") or url.objectid eq application.navid.home) and cgi.SERVER_NAME eq " subsite1.com")
    url.objectid = application.navid.subsite1;

if((not isDefined("url.objectid") or url.objectid eq application.navid.home) and cgi.SERVER_NAME eq " subsite2.com")
    url.objectid = application.navid.subsite2;

</cfscript>


You need to keep in mind when building your subsite templates to reference " application.navid.subsiteX" instead of "application.navid.home", things like links to home, navigation (getDescendants), etc.


And, fingers crossed, that should work.

You can browse the main site at:
  www.mainsite.com

You can browse subsite1 at either:
  www.mainsite.com/go/subsite1/
  www.subsite1.com

  (note interior pages would look like: "www.mainsite.com/go/subsite1/some_page/" or " www.subsite1.com/go/subsite1/some_page"

And you can browse subsite2 at:
  www.subsite2.com


Hopefully not too many errors crept in. Good luck with getting it working how you want.

-Ben

Reply via email to