1. <cfsetting enablecfoutputonly="yes">
  2. <!---
  3. CustomTag: cf_location2
  4. Author: Aaron Longnion, but heavily inspired by Bert Dawson's similar tag
  5. Features:
  6. 1) ability to do Permanent (301) redirects, not just the default of 302
  7. 2) cflocationDebug tells the tag to NOT redirect, but to show the URL and other attributes,
  8. with a handy link to the URL to which you are being redirected. In development or QA,
  9. this allows you do look at what happened *before* the redirect (i.e. important DB updates)
  10. Usage:
  11. <cf_location2
  12. cflocationDebug="[true|false (default)]"
  13. url="location2_test.cfm?test=999"
  14. addtoken="[true|false (default)]"
  15. pageMoved="[Permanent|Temporary (default)]">
  16. --->
  17. <!--- only execute the start tag, not the End tag (if one exists) --->
  18. <cfif ThisTag.ExecutionMode IS "Start">
  19.     <cfparam name="attributes.url" type="string">
  20.     <cfparam name="attributes.addToken" type="boolean" default="false">
  21.     <!--- Temporary (302) or Permanent (301) --->
  22.     <cfparam name="attributes.pageMoved" type="string" default="Temporary">
  23.     <!--- if true, it will not redirect, but rather will --->
  24.     <cfparam name="attributes.cflocationDebug" type="boolean" default="false">
  25. <!--- make sure to get session data into the URL if browser cookies are disabled --->
  26. <cfset variables.url = URLSessionFormat(attributes.url)>
  27.     <!--- very handy for troubleshooting/debugging code with lot's of cflocations --->
  28.     <cfif attributes.cflocationDebug>
  29.      <cfoutput>
  30.             <pre>
  31.                 <strong><em>cflocationDebug</em></strong>
  32.                 <strong>variables.url:</strong> <a href="#variables.url#">#variables.url#</a>
  33.                 <strong>attributes.addtoken:</strong> #attributes.addtoken#
  34.                 <strong>attributes.url:</strong> #attributes.url#
  35.                 <strong>cgi.query_string</strong>: #cgi.query_string#
  36.                 <strong>attributes.pageMoved</strong>: #attributes.pageMoved#
  37.             </pre>
  38.         </cfoutput>
  39.         <cfabort>
  40.     <cfelse>
  41.      <!--- sometimes you want a 301 redirect instead of a 302 --->
  42.      <cfif attributes.moved IS "Permanent">
  43.             <cfheader statuscode="301" statustext="Moved permanently">
  44.             <cfheader name="Location" value="#variables.url#">
  45.             <cfabort>
  46.         <!--- otherwise, do a normal cflocation --->
  47. <cfelse>
  48.             <cflocation url="#variables.url#" addtoken="#attributes.addtoken#">
  49.         </cfif>
  50.     </cfif>
  51. <!--- /ExecutionMode check --->
  52. </cfif>