2

I am running CF10 on IIS 7.5 with URL Rewrite module installed. All the rewrite rules work perfectly and ColdFusion is returning the correct pages. In order to get the page displayed in the browser I have to manually set the 'content-length' value in Application.cfc like this:

<cfcomponent>

  <cffunction name="onRequestEnd">

  <cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#" />

  </cffunction>

</cfcomponent>

Without this code the browser does not display the page. However, even though it is now displaying the page, it is not doing it correctly. The page never finishes loading fully and not all of the HTML content seems to be on the page.

I have tried to add a <cfflush /> tag after setting the 'content-length' but it makes no difference. I don't understand why this is happening but I know that it has happened to someone else who was using htaccess:http://forums.devshed.com/coldfusion-development-84/page-not-finishing -loading-coldfusion-and-htaccess-bug-575906.html

EDIT: Example Outbound/Inbound Rule Definition:

<!--- Outbound rule --->
<rule name="Rewrite Info Page" preCondition="IsHTML" enabled="false" stopProcessing="false">
<match filterByTags="A" pattern="^(.*)/info\.cfm\?subjectid=([^=&amp;]+)&amp;(?:amp;)?nameid=([^=&amp;]+)$" />
<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}&amp;nameid={R:3}" appendQueryString="true" />
</rule>

The Outbound rule is looking at a URL link within an <a> tag that looks like http://mysite.com/info.cfm?subjectid=1&nameid=1 and then rewriting it to appear on my page as http://mysite.com/info/1/1.

The Inbound is looking for a link that looks like http://mysite/info/1/1 and resolving/rewriting it to the real URL which is http://mysite.com/info.cfm?subjectid=1&nameid=1

4

2 回答 2

1

由于 IIS URL Rewrite 的出站规则给您带来了很多麻烦,这里有另一种选择。使用 ColdFusion 重写onRequestEnd. 这将允许您在 IDE 中使用物理路径,使用默认文档,并且仍然以所需格式将出站 URL 发送到浏览器。我已经用细节更新了我的要点

这是一个非常基本的方法。关闭 web.config 中的出站重写规则,并onRequestEndApplication.cfc. (我的正则表达式很糟糕,所以这个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=([^=&amp;]+)', '/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 重写模块那样执行,但它会为您提供您想要实现的所有其他功能(一旦您调整了正则表达式)。

于 2013-09-18T23:45:19.753 回答
1

我能够让您的出站规则在我的本地开发环境中运行(尽管运行 CF9)。唯一的麻烦是将出站规则包装在正确的 XML 元素中。

之后,IIS 告诉我不能将出站规则应用于 gzip 压缩的内容,所以我不得不添加<urlCompression doStaticCompression="true" doDynamicCompression="false"/>到配置中。

有了这些,出站重写工作完美。我什至在一个有超过 20,000 个链接的页面上运行它,它处理得很好。

这是我<rewrite>的 web.config 部分以及以下内容<urlCompression>

    <rewrite>
        <rules>
            <rule name="Rewrite Info" 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}&amp;nameid={R:3}" appendQueryString="true" />
            </rule>
        </rules>
        <outboundRules>
            <rule name="Rewrite Info Page" preCondition="IsHTML" enabled="true" stopProcessing="false">
                <match filterByTags="A" pattern="^(.*)/info\.cfm\?subjectid=([^=&amp;]+)&amp;(?:amp;)?nameid=([^=&amp;]+)$" />
                <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>
            </preConditions>
        </outboundRules>
    </rewrite>
    <urlCompression doStaticCompression="true" doDynamicCompression="false"/>

我发现包含<cfheader name="Content-Length" value="#getPageContext().getCFOutput().getBuffer().size()#" />在结果中没有差异onRequestEnd

但是,由于您正在获取微调器并且页面似乎永远不会完全加载,您可以尝试显式刷新并关闭响应onRequestEnd以确保切换回 IIS 完成:

<cfscript>
    var response = getPageContext().getResponse().getResponse();
    var out = response.getOutputStream();
    out.flush();
    out.close();
</cfscript>
于 2013-09-17T23:56:29.120 回答