Florida SEO Try Catch Application.CFC
Okay, so I am only a year in to CF development now, and I still feeling about as confident with my skills as well, the first month I started ... don't ask me why, but I always seem to find a problem that baffles me. This time is not an exception.
I recently moved to Application.CFC ... (Don't know what that is? Don't worry, I know as much as you. Want to find out more? ... Ray "Raymond" has info on his site ... )
So, this move came about since I had no idea how to manage error handling for 404 pages in CF ... for instance, if a link to a page on my site was missing, or broken ... the 404 page would get returned. However, if someone requested a .cfm page that did not exist whatsoever ... then the "IIS" template would kick in ... Not Good ...
So, I wanted my 404 template to kick in even when someone requested a specific ColdFusion page as well as broken links, moved pages, anything else ...
The only way to get what I really needed ... a default error handler in CF for all pages ... was not going to be available on a shared hosting platform ... which my site is on ... Good thing that ColdFusion 8, has the functionality available by way of the onMissingTemplate function through Application.CFC ...
Now, I saw a few references regarding the cflocation tag ...
<cffunction name="onMissingTemplate" returnType="boolean" output="false">
<cfargument name="thePage" type="string" required="true">
<cflog file="somefiles" text="#arguments.thePage#">
<cflocation url="404.cfm?thepage=#urlEncodedFormat(arguments.thePage)#" addToken="false">
</cffunction>
But this was a problem due to redirecting from a 404 page ... The search engines would definitely have a problem with a 404 page returning a "page moved temporarily" or a "page moved permanently" flag when in fact it didn't exist at all ... That would Not be good for the rankings ...
So, the answer it seems was to try a bit of a different solution ... similar, yet a bit different ... here's the next shot ...
<cffunction name="onMissingTemplate" returnType="boolean" output="true">
<cfargument name="targetPage" type="string" required="true" />
<cflog file="somefile" type="error" text="Missing template: #Arguments.targetPage#">
<cfinclude template="404.cfm" />
<cfreturn true />
</cffunction>
Generally it's not a real smart idea for a newbie coder such as myself to go playing around with really important functions on a production site ... but, then again I can't have problems with 404 pages either ... So, I chanced fate ... and came up with the solution above ...
I also created a custom 404 page which I am rather fond of ... if an event fires my 404 template ... I have an include of my site map so search engine robots can give me a some credit by crawling the sitemap ... and at the same time, I can offer my visitors a useful way to navigate a page that they might have been looking for ...
You have been warned! If, you decide to use a 404 page ... make sure that you don't include it either in your .xml site map ... and that you implement a header status 404 ...
<cfheader statuscode="404" statustext="Not Found" />
Furthermore, pay attention to your Meta Robots Tag ...
<meta name="robots" content="noindex, follow" />
If not ... you are basically telling the search engines that your pages exist ... (status 200 » okay ) ... and that will kill your search engine optimization efforts ... fast.













Shout Out To Shana » The Social Media Sweetheart » Happy Birthday
Shana Albert said: Thank you so much for the birthday wishes, Edward. That is so sweet of you. I'm sorry I didn't tha... [More]