tags:

views:

602

answers:

4

I have a coldfusion web site I need to change. Have no idea or experience with this environment (I do know ASP.NET). All I need to do is to write a condition based on the referral value (the URL) of the page, and redirect to another page in some cases. Can anyone give me an example of the syntax that would perform this?

+1  A: 

Haven't done coldfusion in a little while but:

<cfif some_condition_based_on_your_url>
  <cflocation url="http://where_your_referrals_go"&gt;
</cfif>
<!--- continue processing for non-redirects --->
DanSingerman
+1  A: 

There is a CGI variable scope in ColdFusion that holds information on the incoming request. Try the following:

<cfif CGI.SCRIPT_NAME EQ 'index.cfm'>
    <cflocation url="where you want it to redirect" />
</cfif>

To see what else is available within the CGI scope, check out the following: http://livedocs.adobe.com/coldfusion/8/htmldocs/Expressions_8.html#2679705

Adrocknaphobia
+1  A: 

Lets assume your the URL variable you are basing this on is called goOn (http://yoursite.com?goOn=yes) then the following code would work:

<cfif structKeyExists(url, "goOn") AND url.goOn eq "yes">
    <cflocation url="the_new_url" addtoken="false">
</cfif>

Nothing will happen after the cflocation.

Sam Farmer
+5  A: 

All of the above examples would work...also if you're looking to redirect based on a referral from an external site, you may want to check CGI.HTTP_REFERER. Check out the CGI scope for several other options.

<cfif reFindNoCase('[myRegex]',cgi.http_referer)>
    <cflocation url="my_new_url">
</cfif>

...my example uses a regex search (reFind() or reFindNoCase()) to check the referring url...but you could also check it as a list with / as a delimiter (using listContainsNoCase()) depending on what you're looking for.

RaeLehman
Make sure you prefix your example code with four spaces, otherwise it does not display.Also, note that in the CGI spec, referrer is mis-spelt as HTTP_REFERER
Peter Boughton