How to redirect based on a referral in ColdFusion

I have a coldfusion site that I need to modify. Don't know or are not familiar with this environment (I know ASP.NET). All I have to do is write a condition based on the referral value (URL) of the page and redirect to another page in some cases. Can anyone give me an example syntax that will accomplish this?

+1


source to share


5 answers


All other examples will work ... also if you want to redirect based on referral from an external site you can check CGI.HTTP_REFERER. Check out the CGI area for a few other options.

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

      



... my example uses regex search ( reFind()

or reFindNoCase()

) to check the referenced url ... but you can also check it as a list with /

as delimiter (using listContainsNoCase()

) depending on what you are looking for.

+5


source


Suppose your url variable you are based on is called goOn ( http://yoursite.com?goOn=yes ) then the following code will work:

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

      



After cflocation, nothing happens.

+2


source


Didn't do cold infusion after a while, but:

<cfif some_condition_based_on_your_url>
  <cflocation url="http://where_your_referrals_go">
</cfif>
<!--- continue processing for non-redirects --->

      

+1


source


ColdFusion has a CGI variable area that contains information about 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 in the CGI realm, check the following: http://livedocs.adobe.com/coldfusion/8/htmldocs/Expressions_8.html#2679705

+1


source


Dynamic version.

<cfif isdefined("somecondition")>
    <cfset urlDestination = "someurl">
<cfelseif isdefined("somecondition")>
    <cfset urlDestination = "someurl">
.
.
.
<cfelse>
    <cfset urlDestination = "someurl">
</cfif>

<cflocation url = urlDestination>

      

0


source







All Articles