Subdomain URL redirect using Coldfusion

Posted on 2007-10-04
Last Modified: 2013-12-20
How can I redirect a subdomain URL to a specific directory within my main site using Coldfusion?  I have the subdomain "" and I want to direct it to "".  I tried adding the following code to my application.cfm file but it didn't work:

<cfinclude template="/sub/index.cfm">
<!--- the cfabort is there so it doesn't execute the rest of the application.cfm --->

Any suggestions?  Our sites are hosted so I cannot make any changes to the CF Administrator or at the server level.
Question by:immixGroup
    LVL 4

    Accepted Solution

    <cfif cgi.server_name EQ "">
          <cfset subDomain = listFirst(cgi.server_name, '.') />
          <cflocation url="" addtoken="false" />
    LVL 4

    Assisted Solution

    Improved upon further for a more flxible usage... The second portion of the if statment is in case someone comes to

    <cfset subDomain = listFirst(cgi.server_name, '.') />
    <cfif subDomain NEQ "www" AND subDomain NEQ "mydomain">
          <cflocation url="" addtoken="false" />

    Featured Post

    Free Trending Threat Insights Every Day

    Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

    Join & Write a Comment

    Introduction In this tutorial, I'll explain how to create an animated progress meter in a wireframe prototype developed using Axure RP 7.0 - a leading prototyping tool for designing web sites and software. (For more information about Axure and gett…
    Read about why website design really matters in today's demanding market.
    The purpose of this video is to demonstrate how to add AdSense Ads to a WordPress Website, and how to set up WordPress to automatically place Ads in Sidebars. This will be demonstrated using a Windows 8 PC. Log into your AdSense account. : Cli…
    The purpose of this video is to demonstrate how to set up the permalinks on a WordPress Website. This will be demonstrated using a Windows 8 PC. Go to your WordPress login page. This will look like the following: : Go t…

    755 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    24 Experts available now in Live!

    Get 1:1 Help Now