This post is more than 2 years old.
When I was preparing to move my site from http://ray.camdenfamily.com to http://www.raymondcamden.com, I certainly didn't want all of my old URLs to stop working. I wrote some quick code (literally, I forgot to write the code before hand so I wrote it live on the old server) to handle this. Here is what I did...
First off - I read Pete Freitag's excellent blog post, What CFLOCATION Does, where he talks about how the status code sent out by CFLOCATION is intended for temporary move, not a permanent one. Using the code he suggested, I added a cfheader to my site. However, I have two styles of URLs. I have both traditional query_string style:
And my SEO style cgi.path_info style:
So I needed code to notice either of these two forms. This is what I came up with:
<cfset loc = cgi.script_name> <cfif len(cgi.query_string)> <cfset loc = loc & "?" & cgi.query_string> <cfelseif len(cgi.path_info)> <cfset loc = loc & cgi.path_info> </cfif> <cfset loc = replaceNoCase(loc,"index.cfm/index.cfm","index.cfm")>
<cfheader statuscode="301" statustext="Moved Permanently"> <cfheader name="Location" value="http://www.coldfusionjedi.com#loc#"> <cfabort>
As you can see - I check both cgi.query_string and cgi.path_info. Depending on what is used, I build up my new URL in a variable called loc. I can then push the user there using the two cfheader tags.
Now how does ColdFusion 8 make this easier? The cflocation tag has been updated to allow you to pass in a status code. There is a set of valid status codes, of which 301 is one of them. The two tags above would become one. (Actually I'd be able to get rid of the cfabort as well.)