【问题标题】:SES url in coldfusion - No MVCColdfusion 中的 SES url - 没有 MVC
【发布时间】:2011-07-11 04:25:38
【问题描述】:

得到这个网址

http://localhost:8500/users.cfm?userid=John

通过从数据库中获取用户详细信息来加载用户的个人资料

WHERE userid = <cfqueryparam cfsqltype="CF_SQL_VARCHAR" value="#url.userid#">

如何访问相同的个人资料:

http://localhost:8500/John

用户不必输入“users.cfm?userid=John”,只需输入他们想要查看的人的用户 ID。

在 CF9、IIS7 上

我可能需要安装http://www.iis.net/download/urlrewrite 以获得解决方案,请指教。

感谢您的帮助。

【问题讨论】:

    标签: iis url coldfusion url-rewriting


    【解决方案1】:

    使用 URLRewrite,让重写器将请求的 URL(例如 /John)设置为请求标头,并将其转发到单个 .cfm 文件(例如 front controller)。在 .cfm 文件(例如 frontcontroller.cfm)中读取请求标头(即GetHttpRequestData().headers)并进行相应处理 -> users.cfm?userid=john

    【讨论】:

    • 如果您喜欢使用 OnRequest 或 OnMissingTemplate 的想法,您可以使用 URLRewrite 将 /index.cfm 附加到仅目录请求。不知道 [dis] 的优势是什么。
    • 谢谢,会调查此事。
    【解决方案2】:

    副手,也许您可​​以使用 Application.cfc 中的 OnRequest 方法。该方法允许您过滤请求并对其进行特殊处理。

    http://www.bennadel.com/blog/805-ColdFusion-Application-cfc-OnRequest-Creates-A-Component-Mixin.htm

    在您的示例中,您可以使用“John”或任何字符串(如果它存在于根目录),并且

    <cfinclude template="#application.baseHREF#/users.cfm?userid=#userID#" />
    

    如果您在 OnApplicationStart 中定义 baseHREF。

    【讨论】:

    • 要使用非 .cfm 扩展名,您需要配置 Web 服务器以告诉 CF 处理这些扩展名(例如 .html),我不相信这会处理类似文件夹的请求(即 @987654323 @)。
    • 好点。我没有意识到 ColdFusion 以这种方式受到限制......真可惜。
    【解决方案3】:

    如果您决定使用 ISAPI Rewrite(非免费)之类的工具,它允许您编写类似于 Apache 中使用的重写规则,您需要添加:

    RewriteRule ^(.*)$ /users.cfm?userid=$1 [NC,L,QSA]
    

    您还可以添加文件夹或其他 URL 以从该规则中排除,例如:

    RewriteCond %{REQUEST_URI} !^(assets|images|xml|tasks) [NC]
    RewriteRule ^_admin/(.*)$ /_admin/index.cfm/$1 [NC,L,QSA]
    

    我建议使用重写规则而不是在 CFML 中处理它,以减少 CF 服务器处理的处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-07-15
      • 1970-01-01
      • 2010-11-20
      • 1970-01-01
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多