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?
source to share
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.
source to share
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.
source to share
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
source to share