ColdFusion Simple Friendly URLs

There quite a few methods out there for making search engine and user friendly URLs in ColdFusion eg Spike's Friendly URL servlet or one of the many Apache and IIS URL rewiters.

These are great if your hosting provider has installed them or if you have your own dedicated server. So what do you do if this is not the case or you want to support friendly URLs in a web server agnostic way?

[More]

Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
Sammy Larbi's Gravatar You'll also need to do some work in converting any URLs in forms or links on that page, as if you had links like "somepage.cfm" there, they would now be pointing to "product.cfm/category/books/product/23/somepage.cfm"
# Posted By Sammy Larbi | 4/6/07 1:40 AM
Justin Mclean's Gravatar Right you are, thanks for pointing this out.

There are two solutions I see:
a) Use absolute URLs on any page you want to access via friendly URLs
b) In Application.cfm (or .cfc) look for URL's containing two .cfm's, change the URL to what it should be and do a server side redirect to go to the correct URL.

I'll have a look into the second option to see how viable is it.
# Posted By Justin Mclean | 4/6/07 11:41 AM
Sammy Larbi's Gravatar I've gone the route of b), but I have it done in whatever file parses the URL to figure out what the variables are
# Posted By Sammy Larbi | 4/6/07 3:34 PM
Justin Mclean's Gravatar Actually I've thought of a another way to resolve the issue. Just add a base href to the head section of the HTML page.

Something like this:
<base href="<cfoutput>http://#cgi.HTTP_HOST##ListDeleteAt(cgi.SCRIPT_NAME, ListLen(cgi.SCRIPT_NAME, '/'), '/')#/</cfoutput>" />
# Posted By Justin Mclean | 4/6/07 3:38 PM
Sammy Larbi's Gravatar That's slick. I had to blog about it since I hadn't heard of it... gave you credit though - hope you don't mind =)

http://www.codeodor.com/index.cfm/2007/4/6/Did-you...
# Posted By Sammy Larbi | 4/6/07 11:01 PM
Justin Mclean's Gravatar Thanks Sammy. If you hadn't pointed out the issue I wouldn't of come up with a solution.
# Posted By Justin Mclean | 4/7/07 11:08 AM
andy's Gravatar Please, oh please, let the &lt;base&gt; tag die. It's never been terribly cross-browser friendly and it can wreak all kinds of havok if you're doing anything Flash or AJAX related. Relying on the &lt;base&gt; tag for your web site is the quickest way to end up pulling your hair out later when all kinds of unpredictable things start happening.
# Posted By andy | 6/13/07 3:11 AM
Justin Mclean's Gravatar I've not had any major issues using it. Of course you need to be aware that any URLs on the page (including AJAX calls and Flash swfs) are now relative to the base tag if they were relative URLs. I'm aware there was change in IE7 to bring it more in line with the spec but if it was used correctly you shouldn't have any issues there. What issues have you run into?
# Posted By Justin Mclean | 6/13/07 9:38 AM
glieu's Gravatar Hi,

I am a newbee to Coldfusion. How doyou hide the blog id create with CreateUID() function?

You have something like http://blog.classsoftware.com/index.cfm/2007/3/30/... , how did you translate
/2007/3/30/Simple-Friendly-URLs back to blog id and get the details for Simple-Friendly-URLs?

Please help.

Thank you
# Posted By glieu | 3/28/08 2:25 PM
Justin Mclean's Gravatar I'm using BlogCFC by Raymond Camden.

You can download the code from http://blogcfc.riaforge.org/ to see exactly how he does it.

He uses a similar method to that described above I believe.
# Posted By Justin Mclean | 3/28/08 5:02 PM
Josef Kenny's Gravatar I've not had any major issues using it. Of course you need to be aware that any URLs on the page (including AJAX calls and Flash swfs) are now relative to the base tag if they were relative URLs.
# Posted By Josef Kenny | 5/19/08 4:04 AM
Copyright © Justin Mclean 2008
BlogCFC by Raymond Camden.