Subdomain URL redirect using Coldfusion

How can I redirect a subdomain URL to a specific directory within my main site using Coldfusion?  I have the subdomain "http://sub.mydomain.com" and I want to direct it to "http://www.mydomain.com/sub/index.cfm".  I tried adding the following code to my application.cfm file but it didn't work:

<cfif #CGI.SERVER_NAME# CONTAINS "sub.mydomain.com">
<cfinclude template="/sub/index.cfm">
<!--- the cfabort is there so it doesn't execute the rest of the application.cfm --->
<cfabort>
</cfif>

Any suggestions?  Our sites are hosted so I cannot make any changes to the CF Administrator or at the server level.
immixGroupAsked:
Who is Participating?
 
Russell2566Commented:
<cfif cgi.server_name EQ "sub.mydomain.com">
      <cfset subDomain = listFirst(cgi.server_name, '.') />
      <cflocation url="http://www.mydomain.com/#subDomain#/index.cfm" addtoken="false" />
</cfif>
0
 
Russell2566Commented:
Improved upon further for a more flxible usage... The second portion of the if statment is in case someone comes to http://mydomain.com/...

<cfset subDomain = listFirst(cgi.server_name, '.') />
<cfif subDomain NEQ "www" AND subDomain NEQ "mydomain">
      <cflocation url="http://www.mydomain.com/#subDomain#/index.cfm" addtoken="false" />
</cfif>
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.