Subdomain URL redirect using Coldfusion

Posted on 2007-10-04
Medium Priority
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 "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 --->

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

Accepted Solution

Russell2566 earned 1500 total points
ID: 20015914
<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" />

Assisted Solution

Russell2566 earned 1500 total points
ID: 20015934
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" />

Featured Post

Veeam Disaster Recovery in Microsoft Azure

Veeam PN for Microsoft Azure is a FREE solution designed to simplify and automate the setup of a DR site in Microsoft Azure using lightweight software-defined networking. It reduces the complexity of VPN deployments and is designed for businesses of ALL sizes.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today, the web development industry is booming, and many people consider it to be their vocation. The question you may be asking yourself is – how do I become a web developer?
Q&A with Course Creator, Mark Lassoff, on the importance of HTML5 in the career of a modern-day developer.
The purpose of this video is to demonstrate how to integrate Mailchimp with Facebook. This will be demonstrated using a Windows 8 PC. Mailchimp and Facebook will be used. Log into your Mailchimp account. : Click on your name. Go to Account Setti…
The purpose of this video is to demonstrate how to set up an RSS Feed on a WordPress Website. This will be demonstrated using a Windows 8 PC. Feedburner will be used for this demonstration. Go to your WordPress login page. This will look like the…
Suggested Courses
Course of the Month16 days, 19 hours left to enroll

864 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