Skip to main content
Participant
August 20, 2009
Question

Simple 301 redirect question

  • August 20, 2009
  • 2 replies
  • 2613 views

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.

This topic has been closed for replies.

2 replies

Inspiring
August 25, 2009

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.

Participant
August 20, 2009

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>

BKBK
Community Expert
Community Expert
August 25, 2009

<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">