我正在 IIS 7.5 上运行 CF10,并安装了 URL 重写模块。 所有重写规则都完美运行,ColdFusion 返回正确的页面。为了让页面显示在浏览器中,我必须在 Application.cfc 中手动设置“内容长度”值,如下所示:
<cfcomponent>
<cffunction name="onRequestEnd">
<cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#" />
</cffunction>
</cfcomponent>
如果没有此代码,浏览器将不会显示该页面。但是,即使它现在正在显示该页面,但它并没有正确执行。该页面永远不会完全加载,并且并非所有 HTML 内容似乎都在该页面上。
我尝试添加 <cfflush />
设置“内容长度”后添加标签,但没有区别。我不明白为什么会发生这种情况,但我知道它发生在使用 htaccess 的其他人身上:http://forums.devshed.com/coldfusion-development-84/page-not-finishing -loading-coldfusion-and-htaccess-bug-575906.html
编辑:出站/入站规则定义示例:
<!--- Outbound rule --->
<rule name="Rewrite Info Page" preCondition="IsHTML" enabled="false" stopProcessing="false">
<match filterByTags="A" pattern="^(.*)/info\.cfm\?subjectid=([^=&]+)&(?:amp;)?nameid=([^=&]+)$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
</conditions>
<action type="Rewrite" value="{R:1}/info/{R:2}/{R:3}" />
</rule>
<preConditions>
<preCondition name="IsHTML">
<add input="{RESPONSE_CONTENT_TYPE}" pattern="^text/html" />
</preCondition>
<!--- Inbound rule --->
<rule name="Rewrite Info Page" enabled="true" stopProcessing="false">
<match url="^(.*)/info/([^/]+)/([^/]+)/?$" />
<conditions logicalGrouping="MatchAll" trackAllCaptures="false">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
</conditions>
<action type="Rewrite" url="{R:1}/info.cfm?subjectid={R:2}&nameid={R:3}" appendQueryString="true" />
</rule>
出站规则正在查看 <a>
内的 URL 链接标签看起来像 http://mysite.com/info.cfm?subjectid=1&nameid=1
然后将其重写为在我的页面上显示为 http://mysite.com/info/1/1
。
入站正在寻找类似 http://mysite/info/1/1
的链接并将其解析/重写为真实的 URL,即 http://mysite.com/info.cfm?subjectid=1&nameid=1
最佳答案
由于 IIS URL 重写的出站规则给您带来了很多麻烦,因此这里有另一个选择。使用ColdFusion重写onRequestEnd
中的链接。这将允许您在 IDE 中使用物理路径、使用默认文档,并且仍然能够以所需的格式将出站 URL 发送到浏览器。我有updated my Gist with the details .
这是一个非常基本的方法。关闭 web.config 中的出站重写规则,并将类似的内容添加到 Application.cfc
中的 onRequestEnd
函数中。 (我的正则表达式很糟糕,所以这个 reReplace()
模式只能部分地按照您的 IIS 模式工作。
<cfcomponent>
<cffunction name="onRequestEnd">
<!--- Get the generated output --->
<cfset var output = getPageContext().getCFOutput().getBuffer().toString()>
<!--- Apply outbound link rules --->
<cfset output = reReplace(output, '/info\.cfm\?subjectid=([^=&]+)', '/info/\1', 'all')>
<!--- Clear the previous output and send the rewritten output in its place --->
<cfcontent reset="true">
<cfoutput>#output#</cfoutput>
</cffunction>
</cfcomponent>
这不会像 IIS 中的 URL 重写模块那样执行,但它会为您提供您想要实现的所有其他功能(一旦您调整了正则表达式)。
关于ColdFusion 与 IIS URL 重写 - 页面永远无法完成加载,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18838484/