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?


Comments (Comment Moderation is enabled. Your comment will not appear until approved.)
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
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
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
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
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 =)
# Posted By Sammy Larbi | 4/6/07 11:01 PM
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
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
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

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

You have something like , 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
I'm using BlogCFC by Raymond Camden.

You can download the code from 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
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
I get the following error with this code:

The 2 parameter of the Right function, which is now 0, must be a positive integer

The error occurred in C:\websites\53511bfb\properties\Application.cfm: line 2

1 : &lt;cfscript&gt;
2 : rhs = right(cgi.PATH_INFO,len(cgi.PATH_INFO)-len(cgi.SCRIPT_NAME));
3 : if (rhs neq &quot;&quot;) {
4 : noitems = listLen(rhs,&quot;/&quot;);
# Posted By Eliot Jones | 10/13/10 2:13 AM
Try doing a dump of your cgi scope and looking at cgi.PATH_INFO and cgi.SCRIPTNAME that should give a clue to what is going on.
# Posted By Justin Mclean | 10/13/10 2:32 AM