Reply to topic
Subdomain Redirect Script
cptmorgan


Joined: 24 Jun 2006
Posts: 1
Reply with quote
I'm looking for a coldfusion script to redirect users to a different folder when they come in via a subdomain.

any help would be greatly appreciated.

Thanks
Connie


Joined: 26 Mar 2005
Posts: 174
Location: The Internet
Reply with quote
Here is an example

<CFIF FindNoCase("sub1.domain.com","#CGI.SERVER_NAME#") GT 0>
<CFLOCATION URL="/sub1">
<CFELSEIF FindNoCase("sub2.domain.com","#CGI.SERVER_NAME#") GT 0>
<CFLOCATION URL="/sub2">
<CFELSEIF FindNoCase("sub3.domain3.com","#CGI.SERVER_NAME#") GT 0>
<CFLOCATION URL="/sub3">
<CFELSE>
You came to unknown domain.
</CFIF>
ETA on control panel
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 337
Reply with quote
Is there any eta on when it could be doen in the control panel?
Thanks
not working
jason7655


Joined: 28 Sep 2006
Posts: 3
Reply with quote
any clue why the following wouldn't be working at the top of the application.cfm?

<CFIF FindNoCase("sub1.mysite.com","CGI.SERVER_NAME") GT 0>
<CFLOCATION URL="/sub1">
</CFIF>
I use Contains
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 337
Reply with quote
I have to be honest, that I have never used "FindNOCase", but I have done redirection scripts like that in Application.cfm, and I would do this:
Code:
<cfif #CGI.SERVER_NAME# CONTAINS "sub1.mysite.com">
<cflocation url="/sub1">
<cfelse>
<!-- testing code to verify result of if statement goes here --->
</cfif>

Thanks. But then again, I am a Ruby guy.
jason7655


Joined: 28 Sep 2006
Posts: 3
Reply with quote
Actually, it just doesn't execute. Eventually Firefox says the following:

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

and if I do the following:
<cfdump var="#CGI.SERVER_NAME#">
<cfabort>

I get the correct subdomain.
Got it!
comprug
Forum Regular

Joined: 15 Feb 2006
Posts: 337
Reply with quote
Jason,
I'm glad you provided that error message. I have experienced that error many times, and the simple solution is to add this to the script:
Code:

<cfif #CGI.SERVER_NAME# CONTAINS "sub1.mysite.com">
<cflocation url="http://mysite.com/sub1">
<cfelse>
<!-- testing code to verify result of if statement goes here --->
</cfif>

Basically, what happens, is that as this is in the application.cfm, it is executed again when you are redirected. Since you did not specify the domain, it still contains the sub1 in the domain (I forget the name!?) , so it will execute the code again, redirecting you again - creating an endless loop. Don't worry though; I ALWAYS make that mistake probably just about every time I do redirects.
jason7655


Joined: 28 Sep 2006
Posts: 3
Reply with quote
It appears I got it working doing the following:

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

Well see if I'm still able to do the other things I want to under that sub1.
Subdomain Redirect Script
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic