The HTTP status code of a request is important, particularly for web crawlers like Google or Yahoo! indexing your site. If you get rid of some files (and don't do anything at the IIS or Apache level to redirect users), then you're effectively telling the crawlers that the page still exists with the 200 OK status code.
The fix to the page was easy. Just drop this at the top of your Missing Template Error Handler template:
Note: It's critical that the statustext attribute say "Not Found" and nothing else.
A verification with my handy LiveHTTPHeaders plugin showed that the status code was indeed changed to 404 Not Found.
However, a missing template isn't the only situation where a status code is important. If you move a bunch of files around to better organize your site, keep in mind that search engines have likely already indexed your site or visitors may have bookmarked its location. Since you don't want to generate a bunch of missing template exceptions (regardless of the status code), a cleaner solution (again, barring directives being set in your web server configuration file) would be to specify a status code of 301, which notes that the requested file has been moved permanently. I've seen a lot of code where the developer has just used cflocation to do this. However, cflocation is notably different from a 301 redirect. A cflocation generates a 302 status code, which means that the file has been moved temporarily to a different URL. Hence, search engines will keep the "old" page in its index. However, with this code snippet below at the top of the old page, you can both redirect the user while specifying the more appropriate 301 error code:
For a list of HTTP status codes and their definitions, I highly recommend you bookmark this page (or del.icio.us it or whatever the kids are doing these days).
And remember, the cfheader tag is your friend in these situations.
Have you noticed the CFMX Admin setting for Enable HTTP Status Codes?
-------
Enable HTTP status codes:
Enables ColdFusion to set HTTP error status codes when ColdFusion errors are returned to the browser. ColdFusion sets an error status code of 404 if the template is not found and an error status code of 500 for server errors.
-------
This is on the Settings page, a few lines above the missing template handler.
http://www.forta.com/blog/index.cfm?mode=entry&...
Are there any reasons (from your support experience) why this might need to be turned off? Otherwise, I'll certainly make sure it's on in production.
Err, no. See:
http://www.w3.org/Protocols/rfc2616/rfc2616-sec6.h...
Your 301 example is straight from the documentation, however in my experience it does not work. The second cfheader tag (location) causes CF to reset to the 302 status code. We had a client who was catching fits with Google because of this. The workaround which I found was:
<cfheader statuscode="301" statustext="Moved Permanently#Chr(13)##Chr(10)#Location:site/index.cfm">
FYI, if you issue those two cfheaders, CF continues processing the page. You must manually call cfabort.
This is quite unlike using cflocation which implicitly does a "cfabort" after the cflocation tag is encountered. Just wanted to point this out for anybody using a framework like Mach-II -- without the cfabort there could be some disastrous effects.
Thanks for the help on the <cfheader tag ... I forgot what the correct content"" was supposed to be ...
E
<cfheader name="location" value="http://www.domain.com/">
<cfheader statuscode="301" statustext="Moved Permanently">
<cfabort>
as you were saying that the second cfheader tag (location) causes CF to reset to the 302 status code. if the last cfheader tag is returning 301 then that should be what is ultimately returned in the header response.