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.

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
davidbuhler's Gravatar You'll want to add a cfheader for redirects to previous pages that are missing:
<cfheader statuscode="301" statustext="Moved Permanently">

Also, your best off adding all of the pages in the application scope. Then, add those pages as #application.thePageName# in the Sitemap.xml file. This way, you can manage all the paths to all of your pages in one place.

I also email myself missing templates, so I can add a 301 redirect to the missing page to preserve SER as fast as possible.
# Posted By davidbuhler | 4/20/08 6:25 PM
Edward Beckett's Gravatar I Agree ... I use 301 redirects whenever I have pages that I have moved or decided to delete ... However, putting all the redirects in the application scope I hadn't thought of ... nice ... I don't quite understand what you mean by placing dynamic references in my xml.sitemap ... you might have to elaborate on that one ...

It does get me thinking about the cfxml tag though ...
# Posted By Edward Beckett | 4/21/08 12:26 AM
davidbuhler's Gravatar IN THE APP.CFC ON THE ROOT

<cffunction name="appStart">

<cfif (cgi.SERVER_PORT is 8500)>
<cfset application.http_prefix     = 'localhost:8500' />
<cfset application.https_prefix     = 'localhost:8500' />
<cfelse>
   <cfset application.http_prefix = "http: ~ edwardbeckett.com" />
   <cfset application.https_prefix = "https: ~ edwardbeckett.com" />
</cfif>

<cfscript>   
   application.about_us = application.http_prefix & "content/about_us.cfm";
   application.contact_us = application.http_prefix & "company/contact_us.cfm";
</cfscript>
</cffunction>

<cffunction name="onapplicationStart">
<cfset this.appStart()>
<cfreturn true />
</cffunction>


IN THE FILE THAT GENERATES YOUR SITEMAP.XML

<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http: ~ sitemaps.org/schemas/sitemap/0.9">
<url>
   <loc>#application.about_us#</loc>
   <changefreq>hourly</changefreq>
</url>
<url>
   <loc>#application.contact_us#</loc>
   <changefreq>monthly</changefreq>
</url>
</urlset>
# Posted By davidbuhler | 4/21/08 12:44 AM
Edward Beckett's Gravatar Very nice ... that will definitely come in handy ;-)
# Posted By Edward Beckett | 4/21/08 12:52 AM
davidbuhler's Gravatar I forgot to add the slashes to the domain extension, but it should make sense :)

The goal is to establish the page paths in one location so one change affects your entire website, including the SEO.

For the Redirects (301s), you can rest assured the path the SEO sees in the sitemap is the same one it gets redirected to.
# Posted By davidbuhler | 4/21/08 12:56 AM
Edward Beckett's Gravatar I killed the slashes ... "localhost:8500" doesn't exist on my site ... I'm an seo you know .... ;-)
# Posted By Edward Beckett | 4/21/08 1:24 AM
BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Florida Search Engine Optimization L.L.C.
Search Engine Optimization Specialist || Web Designer || Web Developer || Edward J Beckett ||
Search Engine Optimization Company  || SEO Services || Internet Marketing Company || Search Engine Optimization Expert || Florida Search Engine Optimization LLC
Florida Search Engine Optimization || Search Engine Optimization || SEO Services || Florida SEO Blog
Florida Search Engine Optimization
Search Engine Optimization
SEO Services
Florida SEO Blog
August-20-2008
8:48 PM EST