Creating a 301 redirect with ColdFusion

There are a variety of ways to set up a 301 redirects, here is a very simple way to create them with ColdFusion.  There are also many reasons to create this type of redirect.  Weather you're correcting old indexing in a search engine or making changes to your site structure from a redesign, etc.  This is a powerful and flexible method that is simple to impliment and manage.

The Answer:

<cfheader statuscode="301" statustext="Moved permanently">
<cfheader name="Location" value="http://www.newlocation.com">

The Details:

Being a server side programmaing language ColdFusion can parse information before the web server can so it is simple to create a set of commands that will manage the request and tell the web server how to respond.  This method only works on CFM files that will be processed through the ColdFusion engine.

Create a new file with the file name you need to redirect.  As the request from the browser (either a direct request or from a link in a search engine) is made to this file the ColdFusion engine notifies the browser or search engine that the file has moved, then provides the new location and redirects the request to the new file.

Simply put those lines at the top of your file or create a new file - they must be at the top of the file for a clean redirect.  Everything in the file below this will be ignored.

This is very helpful to intelligent search engines as they will take note of the new location and update their index.  Typically sooner than it's typical indexing rounds to your site.

TIP:

You can do anything in CF code before you do the redirect - as long as you don't send something back to the client browser you can do quite a few things.  Log the request or statistical purposes, process and forward any sesson values or database entries with the new request - and with ColdFusion language it is simple to do.


Was this article helpful?

mood_bad Dislike 0
mood Like 3
visibility Views: 9072