Forum Moderators: open

Message Too Old, No Replies

Wildcard subdomains (2k3 server, IIS6, & Coldfusion)

Windows 2003 Server, IIS 6, Coldfusion 6.1 - setting up wildcard subdomains

         

j0ned

7:17 am on Sep 23, 2006 (gmt 0)

10+ Year Member



Anyone familiar enough with coldfusion to know if interpreting wildcard subdomains is possible? For example..

tutorials.domain.com would redirect to
domain.com/get/subdomaindata.cfm?subdomain=tutorials

or

fubar.domain.com would redirect to
domain.com/get/subdomaindata.cfm?subdomain=fubar

etc.. etc.. If not possible with coldfusion, how would I go about accomplishing this (changing httpd or OS is not an option)?

Reading quite a bit; great community here.

Bluesplinter

11:55 am on Sep 23, 2006 (gmt 0)

10+ Year Member



Parse CGI.SERVER_NAME :)

And welcome to Webmaster World!

[edited by: Bluesplinter at 11:56 am (utc) on Sep. 23, 2006]

j0ned

7:30 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



wrong post

[edited by: j0ned at 7:31 pm (utc) on Sep. 23, 2006]

j0ned

7:30 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



Thanks for the welcoming, this place is great.

Just to clarify, I'd need to include something similar to this in my index.cfm, right? (this is untested)

<cfif #CGI.Server_Name# EQ "tutorials.domain.com">
<cfinclude template="/subdomains/tutorials.cfm">
<cfelseif #CGI.Server_Name# EQ "support.domain.com">
<cfinclude template="/subdomains/support.cfm">
<cfelse>
<regular web-site HTML here for index.cfm>
</cfif>

Thanks for the suggestion! My site is still on my local development server, but I obviously plan on testing some different methods on the production server very soon.

(sorry 'bout the double post)

j0ned

8:02 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



Alright,

So I just tested the code, and with a little modification everything worked as expected.

Thanks for the quick response!

Bluesplinter

8:49 pm on Sep 23, 2006 (gmt 0)

10+ Year Member



That's the idea, but I'd probably reduce it a bit, to something like this for easy maintanence, etc:


<!--- length of the root domain, with the leading dot --->
<cfset domainLength = Len(".domain.com")>

<!--- list of all your usable subdomains --->
<cfset subList = "tutorials,support">

<!--- parse server_name to find subdomain --->
<cfset subDomain = Left(CGI.SERVER_NAME, Len(CGI.SERVER_NAME) - domainLength)>

<!--- see if it matches one in your list --->
<cfif ListContains(subList, subDomain)>

<!--- if matches, load that template --->
<cfinclude template="/subdomains/#subDomain#.cfm">

<!--- if no match, handle error gracefully --->
<cfelse>

<!--- Error Handler --->

</cfif>

Or even better, write a UDF (ie, "subDomain()") with the basic logic, so you can simply do this:

<cfinclude template="/subdomains/#subDomain(CGI.SERVER_NAME)#.cfm">

That would be cleaner, and more modular for future code reuse.

[edited by: Bluesplinter at 9:00 pm (utc) on Sep. 23, 2006]