301 Permanent redirects in ColdFusion

Following on from my previous post, ColdFusion allows redirects by using the cflocation tag. However cflocation is only a temporary redirect and it returns the 302 http moved temporarily header to the browser: The 301 status code is used to indicate that a page has permanently moved, and to do this in ColdFusion we actually […]
Last updated: March 12, 2012

Following on from my previous post, ColdFusion allows redirects by using the cflocation tag. However cflocation is only a temporary redirect and it returns the 302 http moved temporarily header to the browser:

The 301 status code is used to indicate that a page has permanently moved, and to do this in ColdFusion we actually have to create the header with the cfheader tag:

Here we send the browser a header of 301, to say this page is gone, and please now replace it with the URL in the next line. In this case I am dealing with the errors produced by /software/ and sending them to the home page because thats as good as any. This will stop my webserver logs being clogged up with 404 errors for the software directory. Another way of doing 301 redirects is to get your webserver to do them, however that means you need admin access to either the IIS console or to Apache httpd.conf files. Another good use of this code is for Search Engine Optimisations. If your site responds with and without the www e.g.:

Then your search engine rankings will be diluted because they are treated as completely different sites. So lining them up so that they only respond on one domain is really a good thing.

Duncan Isaksen-Loxton

Educated as a web developer, with over 20 years of internet based work and experience, Duncan is a Google Workspace Certified Collaboration Engineer and a WordPress expert.
Login
Log in below to access your courses.
Log In With Google
Forgot Password
Enter your email address or username and we’ll send you instructions to reset your password.