<cfsetting enablecfoutputonly="yes">
<!---
CustomTag: cf_location2
Author: Aaron Longnion, but heavily inspired by Bert Dawson's similar tag
Features:
1) ability to do Permanent (301) redirects, not just the default of 302
2) cflocationDebug tells the tag to NOT redirect, but to show the URL and other attributes,
with a handy link to the URL to which you are being redirected. In development or QA,
this allows you do look at what happened *before* the redirect (i.e. important DB updates)
Usage:
<cf_location2
cflocationDebug="[true|false (default)]"
url="location2_test.cfm?test=999"
addtoken="[true|false (default)]"
pageMoved="[Permanent|Temporary (default)]">
--->
<!--- only execute the start tag, not the End tag (if one exists) --->
<cfif ThisTag.ExecutionMode IS "Start">
<cfparam name="attributes.url" type="string">
<cfparam name="attributes.addToken" type="boolean" default="false">
<!--- Temporary (302) or Permanent (301) --->
<cfparam name="attributes.pageMoved" type="string" default="Temporary">
<!--- if true, it will not redirect, but rather will --->
<cfparam name="attributes.cflocationDebug" type="boolean" default="false">
<!--- make sure to get session data into the URL if browser cookies are disabled --->
<cfset variables.url = URLSessionFormat(attributes.url)>
<!--- very handy for troubleshooting/debugging code with lot's of cflocations --->
<cfif attributes.cflocationDebug>
<cfoutput>
<pre>
<strong><em>cflocationDebug</em></strong>
<strong>variables.url:</strong> <a href="#variables.url#">#variables.url#</a>
<strong>attributes.addtoken:</strong> #attributes.addtoken#
<strong>attributes.url:</strong> #attributes.url#
<strong>cgi.query_string</strong>: #cgi.query_string#
<strong>attributes.pageMoved</strong>: #attributes.pageMoved#
</pre>
</cfoutput>
<cfabort>
<cfelse>
<!--- sometimes you want a 301 redirect instead of a 302 --->
<cfif attributes.moved IS "Permanent">
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="#variables.url#">
<cfabort>
<!--- otherwise, do a normal cflocation --->
<cfelse>
<cflocation url="#variables.url#" addtoken="#attributes.addtoken#">
</cfif>
</cfif>
<!--- /ExecutionMode check --->
</cfif>