Simple 301 redirect question
Copy link to clipboard
Copied
I am not a ColdFusion developer - I need help with 301 redirect code.
I am working with a company that has multiple websites and one of them is a ColdFusion site. They would like to redirect two pages. I found the following 301 redirect code, but I don't know where to place it in the page, or how to wrap them in a CF tags.
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value=http://newsite.com/newpage.cfm>
Is this propper code?
Can someone suggest a site that shows the complete code - if it should be in the header, it would be great to see an example that includes the header tags.
Thank you in advance - Tracy.
Copy link to clipboard
Copied
I put it between the header tags
<header>
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value=http://newsite.com/newpage.cfm>
</header
For some reason the code I found had a period right before the code - I took it out and it worked:
instead of this:
<.cfheader statuscode="301" statustext="Moved permanently">
<.cfheader name="Location" value=http://newsite.com/newpage.cfm>
Used this
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value=http://newsite.com/newpage.cfm>
Copy link to clipboard
Copied
<header>
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value=http://newsite.com/newpage.cfm></header>
Not quite. Three things:
1) I think you mean HTML's head tag, not header.
2) Coldfusion has been known to spawn a thread that goes past the two tags. So, end it with a cfabort, thus
<head><title>Title of document</title>
<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="http://newsite.com/newpage.cfm"><!--- quotes added! --->
<cfabort>
</head>
3) If you're on Coldfusion 8 or newer, use, in place of the 2 header tags, the cflocation tag, thus
<cflocation url="http://newsite.com/newpage.cfm" statuscode="301" addtoken="false">
Copy link to clipboard
Copied
Actally the <cfheader> tag creates HTTP headers, not HTML <head> Meta tags.
As such it just goes in the page. When CFML runs that command it will create the desired HTTP headers which will then be returned to the web server when the entire http reqeuest has been processed.
The dot you found in the code example was a lazy trick by the original author to display the code without it being interperted by the browser as an unknown html tag <unknown tag> which would then not be displayed. So yes, you remove the extranous dots.
It sounds like, for the purpose of your task, your page would consist soley of these to HTTP header tags.
HTH
Ian
Copy link to clipboard
Copied
The distinction between the HTML tags and the corresponding ColdFusion tags is important...
By using the proper ColdFusion tags, you inform ColdFusion that, when it ("in just a few moments...") prepares the output to be sent to the user, the output should include those HTML tags. (In the case of <cflocation> you don't even have to say what the tags are.)
Whereas languages like PHP are "strictly in-line," and therefore will throw bogosities like "output has already begun," ColdFusion interprets your page content in a "declarative" way, then uses its own separate code to generate the final output. It is possible for you to exert specific influences on that process (telling it to "flush the buffers now" and so-forth) but generally you don't have to.
It takes a little "mental gear-shifting" to grok what's going on if you're coming from another world like PHP, but once you do, it's quite refreshing.

