Quackit Logo
HTML
CSS
Scripting
Database
Hosting
Design
XML
Website builder

ColdFusion Redirect

If you're familiar with HTML, you may have learned how to perform a URL redirection using the meta tag. If not, you can learn how to do that in 30 seconds on this HTML redirect page.

In ColdFusion, redirects can be done via one of two methods. The method you use will depend on the reason for the redirect.

Temporary Redirects (cflocation)

This is the most commonly used of the two - you will probably find yourself using the cflocation tag often.

A temporary redirect is typically used when you need to redirect the user to another page based on some logical rule in your program. For example, straight after they submit a form, the browser might redirect to another page.

ColdFusion includes the cflocation tag for performing temporary redirects. This actually sends HTTP headers to the user's browser indicating a 302 status code, which means "Moved Temporarily".

<cflocation url="/new_location.cfm">

Permanent Redirects

A permanent redirect should be used when a page no longer exists.

Permanent redirects use the 301 HTTP status code, which means, "Moved Permanently". In ColdFusion, a permanent redirect can be achieved using the cfheader tag.

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

In case you're thinking, "but users can't see the status code anyway", that's only partially true. The 301 status code can be very useful for search engines. They will actually take notice of your 301 status code and index the correct file.

Enjoy this page?

  1. Add this page to your Favorites
  2. Link to this page (copy/paste into your own website or blog):
  3. Link to Quackit using one of these banner ads.

Thanks for supporting Quackit!