What CFLOCATION Does

coldfusionweb

It is often stated that CFLOCATION does a client side redirect. This means that it sends back some HTTP headers telling your browser to request a different location. This is done with a 302 (Moved Temporarily) HTTP status code, and the Location header. Here's what the HTTP response might look like:

HTTP/1.1 302 Moved Temporarily
Content-Type: text/html; charset=UTF-8
location: /anotherPage.cfm 
Connection: close 
Date: Mon, 16 May 2005 18:27:21 GMT 
Server: Apache

CFLOCATION should only be used for temporary redirects.

For permanent redirects use the 301 HTTP status code, which stands for Moved Permanently. You can do this with the CFHEADER tag:

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

It is important that you use the correct status text Moved Permanently as defined by the HTTP RFC.



Related Entries

33 people found this page useful, what do you think?

 Download FuseGuard WAF for ColdFusion

Trackbacks

Trackback Address: 359/E872918E745FE54E8957C3CC8D47C8E2

Comments

On 05/16/2005 at 10:24:00 PM EDT Raymond Camden wrote:
1
Can you elaborate why a person shouldn't use cflocation? I know of almost no one who uses it for permanent moves. They almost always use it to move the user. So for example, when a form is submitted, they will use it to push them away so that they can't reload an accidently refresh the form post. Or they use it to push yhou to a main page after a login. In other words - I think 99% (or even 100%) of CFML developers are using cflocation in what you would call the wrong way. While I see your point - do you really feel it is important enough for folks to rip out all their cflocations and switch to those 3 lines of code? What exactly is going to go wrong if they do not? I'm not trying to be argumenative (although I do feel you won't convince folks to give up on cflocation), but I would like you to explore this a bit more.

On 05/16/2005 at 11:54:28 PM EDT barry.b wrote:
2
hey Peter

can you define "Moved Temporarily" Vs "Moved Permanently" ?

- especially in the context of "just using the cflocation tag" when you've finished processing a form and want to redirect the user (and deliberatly don't want to - or can't - use

getPagecontext().forward()

or are you saying that MACR have got it wrong and cflocation should be changed?

thanx barry.b

On 05/17/2005 at 12:38:12 AM EDT Pete Freitag wrote:
3
No I'm not saying that it's worth changing your CFLOCATION tags to do permanent redirect in most cases.

I think the main benefits to not using a CFLOCATION to do a redirect are for SEO reasons... So for instance if you have a domain called 8ball.com, and you also own eightball.com - using a CFLOCATION to do redirects from eightball.com to 8ball.com is a bad idea from a SEO standpoint.

Ray the cases your point out I think are indeed temporary redirects, I'd use cflocation for those.

So permanent redirects are things like if you delete an ID and it no longer exists you want to do a perm redirect to the main articles listing, instead of a cflocation.

On 07/19/2005 at 5:17:10 PM EDT Chris wrote:
4
Have you had any issues using this in Firefox? Trying to do permanent redirect for search engine spiders and code works in most browsers, but hangs or spits out processed HTML in Firefox 1.0.4+ or Netscape 8.0+. Any suggestions?

On 07/19/2005 at 6:29:01 PM EDT Pete Freitag wrote:
5
Chris,

No I haven't had any problems with this in firefox. Make sure your using the proper status text "Moved Permanently"

On 09/18/2005 at 1:09:45 PM EDT Merlinox wrote:
6
Why is important to do it? If I use cflocation in a "DNS" page which command is better? DNS page (for me): I analyze servern_name (domain) and I redirect user on right folder/page. Thanks

On 01/11/2006 at 10:14:35 PM EST Kevin wrote:
7
on a FORM page, sent to an ACTION page, cflocated to somewhere else, it does not matter that you are using a 302 redirect... as soon as you hit the submit button, you've gon to places searhc engine will not. the 302 status is refering to the page you are cflocating from, since it is the page you are saying has temporarily moved. Once the desination page is reached, your got a 202 OK status code. So as far as SEO goes, it matters not to use cflocation with a FORM page.

However, If you are doing something like chcing domain names in your application.{cfm|cfc} then you want to be sure that you use a 301 redirect, indication that the move is permanent, and search engine will index it just fine. They don't like temp redirects (302) why should they index something marked as temporary?

On 02/06/2006 at 3:43:52 PM EST darren wrote:
8
is it a good idea to setup 301 redirects from www.mysite.com to www.mysite.com/home.cfm? we are currently using clocation on the index.cfm to send them to the home.cfm. Thanks!

On 06/28/2006 at 11:52:31 PM EDT Pete Freitag wrote:
9
Darren, in your case yes you would want to use a 301.

But I have to ask why redirect to home.cfm to begin with?

On 06/29/2006 at 2:41:26 AM EDT Merlinox wrote:
10
I change all my /index.cfm DNS page on shared hosting with your suggest. I create a function location(page) with 2 cfheader and 301 redirection!

Thanks

On 07/24/2006 at 4:18:42 PM EDT Jeff Osborn wrote:
11
I was having a problem using cflocation with a url that has both a parameter and a location.

For example: .../mydomain.com/mypage.cfm?param1=value#location

In this case I have an anchor on mypage.cfm called ?location? and I want to point the browser at it. I also have a parameter called param1 with a value of ?value?.

It seems that the cflocation tag dose not parse this url properly and, at lease in my case, I was actually getting the location tacked onto the back end of cftoken. Needless to say it wreaked havoc on my session.

The three lines provided above work out for me with the following stipulation. The url had to be page name followed by the parameter followed by the location, as shown above. It would not work if the location followed the page name and preceded the parameter. Go figure.

Thanks for the cold fusion insight,

Jeff

On 07/24/2006 at 4:25:43 PM EDT Merlinox wrote:
12
You must use double ## for escape CF # real value and use HTML # real value (anchor).

On 07/24/2006 at 4:31:28 PM EDT Jeff Osborn wrote:
13
Yes, two # if it is contained within cfoutput tags, and one if not. I was still getting the same results until I tried the 3 lines above. Thanks, Jeff

On 09/13/2006 at 7:17:23 AM EDT Anonymous wrote:
14
I am trying to post, but it all the time says i can't post because i used words which i am not allowed :-(

It fails (however) to tell me which words. And as it is a rather long text i can't just 500x try and error it :-(

On 12/13/2006 at 3:52:37 PM EST NTA wrote:
15
Every header test tool I have used to test my pages that have a CFLocation have returned a valid 301. What test tool are you using?

On 01/03/2007 at 11:49:33 AM EST Pete wrote:
16
I have a simple set of code in place that redirects users to a URL in order to provide a method of tracking where people go outside of our main website (external links).

cflocation seems to bind threads, causing timeouts to occur. Is there an inherent performance problem with cflocation?

Post a Comment




  



Spell Checker by Foundeo

Recent Entries



foundeo


did you hack my cf?