Model-Glue, SES URLs, and Event Redirection

I ran into an interesting problem this morning when working on the ColdFusion Cookbook site. I was adding some protection in for URL variables. Right now when you link to a category, it looks like so:

http://dev.coldfusioncookbook.com/category/6/Forms

(Minus the dev of course. ;)

This translates via URL rewriting to:

http://dev.coldfusioncookbook.com/index.cfm?event=showCategory&id=6

I wanted to validate that the ID was a valid one. Luckily the rewrite just ignore non-numeric numbers. So if you change 6 to apple, you get a 404. (I should probably fix that as well.) But if you change 6 to 600, you got an empty page.

So this was easy enough to handle in the controller. I added code like so:

<cfif category.getID() is "0"> <cfset arguments.event.addResult("invalid") />

Then my ModelGlue.xml had:

<result name="invalid" do="Home" redirect="yes"/>

This basically said - if an invalid result was added to the event, push em back to the home page. However - when I tested - I got an infinite redirection error in Firefox. (Hey, thank God at least Firefox recognizes that.) Turns out it was trying to go here:

http://dev.coldfusioncookbook.com/category/6/Forms/index.cfm?event=Etc

Notice how it didn't remove the SES information? Turns out there is a setting in the core Model-Glue code that says what the "home" URL is. This setting is called self. You can override this in your own ModelGlue.xml, as I did here:

<setting name="self" value="/index.cfm" />

Thanks go to Doug Hughes for this idea! (And sorry Doug for forgetting your credit on the first post!)

Archived Comments

Comment 1 by Mark Mazelin posted on 1/24/2006 at 10:50 PM

Ray,

Thanks for publishing your cookbook code. It really helps those of us that are trying to forge our way into the MG world. I was looking through your cookbook code to see how you implemented the SES rewriting, but I couldn't find it anywhere. I'm sure I'm just looking right over it (my wife says I do it often), so could you point me in the right direction?

Thanks,
Mark

Comment 2 by Raymond Camden posted on 1/24/2006 at 11:14 PM

It's all done with ISAPIRewrite.

Comment 3 by Mark Mazelin posted on 1/25/2006 at 12:07 AM

Well I guess that would explain why I didn't see it. I was looking for something like what you put in the blogcfc, hence my confusion. Now I can tell my wife that I didn't miss it because it wasn't there! :-)

Thanks.