我可以在没有 IIS 中的 URL 重写器的情况下拥有“友好"的 url 吗? [英] Can I have 'friendly' url's without a URL rewriter in IIS?
问题描述
如果没有可用的 URL 重写器(例如 ISAPI_Rewrite),是否可以实现以下目标:
Without having a url rewriter such as ISAPI_Rewrite available, is it possible to achieve the following:
我希望用户浏览到 http://www.jjj.com/directory
,其中 /directory
实际上并不存在.IIS 将用户转移到 not-found.cfm
.
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
.
此时我可以提供 index.cfm
即 http://www.jjj.com/directory/index.cfm
.
At this point I can serve index.cfm
i.e. http://www.jjj.com/directory/index.cfm
.
即使目录或 index.cfm
不存在,URL 也会正常显示并加载页面.但是我希望能够在 url 中没有 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.
理想:
对
http://www.jjj.com/directory
的页面请求
IIS 加载 not-found.cfm
作为默认的 404
错误处理程序.
IIS loads not-found.cfm
as the default 404
errorhandler.
Not found 会去除 CGI.query_string
并使用 cfswitches
将用户引导至适当的控制器功能.可以使用 onMissingTemplate
吗?
Not found strips the CGI.query_string
and uses cfswitches
to funnel the user to the appropriate controller function. May use onMissingTemplate
?
页面请求在 URL 中永远不会改变,页面以 200 OK
状态透明加载用户
The page request never changes in the URL and the page loads transparently the user with 200 OK
status
如果用户请求 http://www.jjj.com/directory/index.cfm
我会 301
重定向到 http:///www.jjj.com/directory
If a user requests http://www.jjj.com/directory/index.cfm
I would 301
redirect to http://www.jjj.com/directory
当前:
对
http://www.jjj.com/directory
的页面请求
IIS 加载 not-found.cfm
作为默认的 404
错误处理程序.
IIS loads not-found.cfm
as default 404
error handler.
Not found 会去除 CGI.query_string
并使用 cfswitches
将用户引导至适当的控制器功能.
Not found strips the CGI.query_string
and uses cfswitches
to funnel the user to the appropriate controller function.
页面请求更改为 http://www.jjj.com/directory/index.cfm
,状态为 200 OK
The page request changes to http://www.jjj.com/directory/index.cfm
with a 200 OK
status
推荐答案
你问怎么剪东西,但告诉我们你不能用刀或类似的东西.
You're asking how to cut something but telling us you're not allowed to use a knife or anything resembling one.
这是我使用 onMissingTemplate()
的唯一聪明点子.
Here's my only clever idea using onMissingTemplate()
.
GET/directory/
-> 404.cfm
-> <cfinclude template="#cgi.script_name#/special.cfm"/>
-> 触发 onMissingTemplate()
,您忽略special.cfm"位,只需使用请求路径的其余部分来确定要连接到哪个控制器.
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.
不过,这是一个笨拙的 hack,所以我自己会尽量避免它.也许如果您解释为什么 ISAPI 重写不是一个选项,那么我们也许可以提供进一步的帮助.
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.
这篇关于我可以在没有 IIS 中的 URL 重写器的情况下拥有“友好"的 url 吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!