What CFLOCATION Does
By Pete Freitag
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="https://www.petefreitag.com/"> <cfabort>
It is important that you use the correct status text Moved Permanently as defined by the HTTP RFC.
What CFLOCATION Does was first published on May 16, 2005.
If you like reading about redirect, http, cfheader, cflocation, or cfml then you might also like:
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.
Try Fixinator
CFBreak
The weekly newsletter for the CFML Community
Comments
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
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.
No I haven't had any problems with this in firefox. Make sure your using the proper status text "Moved Permanently"
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
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?
But I have to ask why redirect to home.cfm to begin with?
I create a function location(page) with 2 cfheader and 301 redirection!
Thanks
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
cflocation seems to bind threads, causing timeouts to occur. Is there an inherent performance problem with cflocation?