New StatusCode Attribute in CFLOCATION

by Pete Freitag

When ColdFusion 7 came out I did a series of blog entries on small often overlooked new features. Well ColdFusion 8 is now out, and I thought it would be a good idea to do the same.

One handy new feature in ColdFusion 8 is the statusCode attribute in the CFLOCATION tag. I wrote a blog entry a while back called What CFLOCATION Does? - it explains that CFLOCATION does an HTTP 302 Moved Temporarily

redirect. Often times for SEO reasons you will want to do an HTTP 301 Moved Permanently redirect. When a search crawler sees a 301 redirect it forward all pagerank, backlinks, google juice, whatever you want to call it - on to the new url.

In the past you would have had to do something like this to do a 301 redirect with ColdFusion:

<cfheader statuscode="301" statustext="Moved Permanently">
<cfheader name="Location" value="https://www.petefreitag.com/">
<cfabort>

Now, in ColdFusion 8 you can simply use the CFLOCATION tag with the statusCode attribute:

<cflocation url="https://www.petefreitag.com/" statuscode="301" addtoken="false">

According to the documentation the statusCode attribute accepts the following status code values: 300, 301, 302, 303, 304, 305, 307

The Fixinator Code Security Scanner for ColdFusion & CFML is an easy to use security tool that every CF developer can use. It can also easily integrate into CI for automatic scanning on every commit.

Comments

BigTallGeoff

great info, thanks Pete!

Steve

thanks for the cool info, I wasn't aware of this