views:

69

answers:

3

Without having a url rewriter such as ISAPI_Rewrite available, is it possible to achieve the following:

I would like a user to browse to http://www.jjj.com/directory where /directory does not actually exist. IIS transfers the user to not-found.cfm.

At this point I can serve index.cfm i.e. http://www.jjj.com/directory/index.cfm.

The url will display just fine and the page loads even though the directory or index.cfm doesn't exist. However I'd like to be able to not have index.cfm in the url.

Ideal:

  1. Page Request to http://www.jjj.com/directory

  2. IIS loads not-found.cfm as the default 404 errorhandler.

  3. Not found strips the CGI.query_string and uses cfswitches to funnel the user to the appropriate controller function. May use onMissingTemplate?

  4. The page request never changes in the URL and the page loads transparently the user with 200 OK status

  5. If a user requests http://www.jjj.com/directory/index.cfm I would 301 redirect to http://www.jjj.com/directory

Current:

  1. Page Request to http://www.jjj.com/directory

  2. IIS loads not-found.cfm as default 404 error handler.

  3. Not found strips the CGI.query_string and uses cfswitches to funnel the user to the appropriate controller function.

  4. The page request changes to http://www.jjj.com/directory/index.cfm with a 200 OK status

+2  A: 

You're asking how to cut something but telling us you're not allowed to use a knife or anything resembling one.

Here's my only clever idea using onMissingTemplate().

GET /directory/
-> 404.cfm
-> <cfinclude template="#cgi.script_name#/special.cfm" />
-> fires onMissingTemplate() where you ignore the "special.cfm" bit and just use the rest of the requested path to figure out what controller to wire up to.

This is a kludgy hack, though, so I would try to avoid it myself. Maybe if you explain why ISAPI Rewriting isn't an option, then we might be able to help further.

Adam Tuttle
Adam - Military. Systems administrators found that ISAPI is not on their safe to use list. It's not credentialed.
Jason Tabler
Adam - #cgi.script_name# for me, when I'm on my 404.cfm (not-found.cfm) page is not-found.cfm. The only place with the url and namevalue pairs is cgi.query_string. This what I referred to as breaking the request. Thanks for the help!
Jason Tabler
Ok, yeah, I didn't test the code, so you'll need to use something other than cgi.script_name. The principal will be the same, though. Regarding "Not Credentialed" - can you give more information? I mean, I get that the military is going to set some rules and you won't have much wiggle room, but that seems a bit unreasonable to me. You can't require something (the url formats you're looking to create) **AND** take away the tools that make it possible.
Adam Tuttle
To restate: this is a problem that has been solved; but your requirements are that you not use the existing solution. You might be better off trying to get the rule changed, imo. Still, I'd love to know more about why ISAPI Rewriting is not considered safe.
Adam Tuttle
Adam - The military has a safe list of software. Unless ISAPI rewrite is on there, then it is not considered safe. Now that isn't to say that it will never be safe, it's just that nobody has filled out the 40 page application and done the research and interviews with the developers to determine that it is safe! No only that, the sys admins here are pretty conservative when it comes to change, even for permissible software.
Jason Tabler
I'm not so sure the problem is solved. I haven't got it all working quite yet. However, I'll supply more info next week as I finish up the recode to get the 301s working. I'm currently stuck in a loop. I was really kind of looking for a more elegant solution, but you're right that we're pretty limited with this square peg-round hole solution.
Jason Tabler
When I said that the problem was solved, I was implying that the solution is one of the available ISAPI Rewrite extensions. If the requirements state that the URLs have to have the format you desire, then you're either going to have to use the "unsafe" software that millions (billions?) of websites have been using for a decade with no exploits currently in use, or you're going to have a kludgy hack that may not work well, if at all.
Adam Tuttle
Alternately, you can just give up on your desire to not have ".cfm" in the url. You could minimize it by using a front-controller framework that routes all requests through index.cfm, so that there is only ever 1 .cfm.
Adam Tuttle
Adam - I can't do much about ISAPI, but wait for IIS7. My hands are tied on that one. I wasn't so concerned about the .cfm, but the problem is that it needs to work without the .cfm. It boils down to the fact that without a cfm you can hack your way through stuff successfully with the cgi.query_string. However, you have an entirely different effort with not found .cfm templates due to onMissingTemplate which allows preservation of the CGI scope as you'd expect.
Jason Tabler
Unfortunately, it looks like I'll have to do what I thought I'd be forced to do. I have one solution using the 404 page and one solution if a .cfm is present. This is the only way I could be sure to trap all requests and have them all pointing at one working url that doesn't allow duplicate content into the search engines. Once I get rewriting, I can do away with the ugly code without disrupting the URL (hopefully!).
Jason Tabler
A: 

You can tell IIS to have 404 and 403 errors execute a custom URL on your site (such as /urlhandler.cfm).

Then, you can parse the 'cgi.query_string' and route the application anyway you desire using cfinclude to simply include the correct 'template.cfm', or, you can reformat the input your framework is expecting, or, use a project like http://coldcourse.riaforge.org/.

Just one note, IIS will give you a URL that looks like this: '404;http://yoursite.com/the/url/you/wanted/to/route'.

Aaron Greenlee
A: 

Is IIS7 on the approved list of software? That can get you native url rewriting and side-step the whole issue.

Second option -- my CFM voodoo is rusty, but I think you can setup IIS6 to look for a CFM page (like you are doing) but then step in at the application level and do the url rewriting/repointing before it actually hits the 404 page.

Another way around it -- find an ISAPI url rewriter that is, say, under the MIT license. Build your own copy. Then have them install that as part of your software package.

Wyatt Barnett
IIS7 is approved and is on the to do list within the next year. So, it will 'eventually' be the go to solution. However, next year could be next two years as you can imagine. You also propose a great work around, but custom built software also has to go through the same approval channel as commercial software, unfortunately. It's also not any easier to gain approval.
Jason Tabler
Gotcha. Then punching everything through coldfusion and then handling the URL at the application level is the way to go. Done that quite a bit in the IIS6 days, it does work though you can kill yourself when it comes to scaling. Best of luck.
Wyatt Barnett