ColdFusion Redirect

You can use ColdFusion to do a server-side redirect, where users are redirected from a URL to another.

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.

The HTML method performs a client-side redirect. ColdFusion is a server-side language, and so any redirect you create in ColdFusion will be a server-side redirect.

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

Permanent Redirects

A permanent redirect should be used when a page no longer exists, and has moved permanently to a new location.

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

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.