问题
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:
Page Request to
http://www.jjj.com/directory
IIS loads
not-found.cfm
as the default404
errorhandler.Not found strips the
CGI.query_string
and usescfswitches
to funnel the user to the appropriate controller function. May useonMissingTemplate
?The page request never changes in the URL and the page loads transparently the user with
200 OK
statusIf a user requests
http://www.jjj.com/directory/index.cfm
I would301
redirect tohttp://www.jjj.com/directory
Current:
Page Request to
http://www.jjj.com/directory
IIS loads
not-found.cfm
as default404
error handler.Not found strips the
CGI.query_string
and usescfswitches
to funnel the user to the appropriate controller function.The page request changes to
http://www.jjj.com/directory/index.cfm
with a200 OK
status
回答1:
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.
回答2:
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'.
回答3:
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.
来源:https://stackoverflow.com/questions/3677895/can-i-have-friendly-urls-without-a-url-rewriter-in-iis