Creative Juices Bo. Co.

Satisfy Your Thirst For Something Refreshing!

ColdFusion and Dynamic SES (Search Engine Safe) URL's : Part 2

Revisiting SES's

If you read my last post on Search Engine Safe (SES) URL's, you may have noticed that it was pretty basic. But like everything I post, it's kind of a work in progress.

Anyways, I've been working on a project and I had to revisit using SES's and I discovered another trick. Basically what I had before, using a URL parameter, should still be valid. If you don't remember, it looked something like this:

http://www.whatever.com/products.cfm?id=2369/accessories/gloves/Fuzzy+Pink+Mittens/

I've been tracking a few of my websites using Google Analytics and so far this method seems to be working fine. The one thing that bothers me though, is that I still see sites using another method, and I couldn't figure out how they were doing it. Basically the URL looks something like this:

http://www.whatever.com/index.cfm/accessories/gloves/Fuzzy+Pink+Mittens/

Notice how they are not using a URL parameter? Yeah, that boggled me nogg'n. So I did some digging and some experimenting and here's what I came up with. Basically you can pull the part that's after the index.cfm by checking the CGI.PATH_INFO parameter.

<cfoutput>#CGI.PATH_INFO#</cfoutput>// Result --> /accessories/gloves/Fuzzy+Pink+Mittens/

Now that I have this information I can use it for whatever my needs might be. QUERY's, CFC's, etc. I've made a little function that will return the results into an array.

<cffunction name="getCurrentPath" output="No" returntype="Array">
   <cfif CGI.PATH_INFO contains "&">
      <cfset url_str = ListGetAt(CGI.PATH_INFO,1,"&")>
   <cfelse>
      <cfset url_str = CGI.PATH_INFO>
   </cfif>
   <cfset url_str = REReplaceNoCase(url_str,"^\/|\/$","","ALL")>
   <cfset url_array = ListToArray(url_str,"/")>
   <cfloop index="i" from="1" to="#ArrayLen(url_array)#">
      <cfset url_array[i] = URLEncodedFormat(url_array[i])>
   </cfloop>
   <cfreturn url_array />
</cffunction>

This would return these results with the same example above:

[0] accessories[1] gloves[2] Fuzzy+Pink+Mittens

The only other thing I would like to figure out is how they do the same thing without actually using the index.cfm in the URL. Is suspect that this is done with ColdFusion 8, since you are able to use the Application.cfc which allows you to use onRequestStart method. Basically this is called before the page load, but I haven't played with this much yet. I'll be sure to let you know!