【问题标题】:IIS URL Rewrite with ColdFusion keeps duplicates string使用 ColdFusion 重写 IIS URL 会保留重复的字符串
【发布时间】:2020-01-13 22:14:44
【问题描述】:

我已经设置了一个 URL 重写,当我手动设置或输入 URL 时它可以正常工作。但是,当我在页面中使用 <cfoutput> 标记中的链接时,该链接会复制字符串。

我正在使用带有 IIS 10 的 ColdFusion 2016

例如网址是

www.site.com/results.cfm?lang=1&categoryid=2&budegtid=all&typeid=all&propertyid=316

我希望它像这样输出

www.site.com/properties/en/all/all/all/316

它可以工作,但是当我使用...设置链接时似乎发生了什么 <cfoutput> 使用查询...

<cfif getProps.recordcount>
<cfoutput query = "getProps" startrow="#url.start#" maxrows="#perpage#">
<a href="property/#lang#/#category_id#/#budgetid#/#typeid#/#getProps.property_id#" id="listVewButton">View</a>
</cfoutput>

页面链接中的结果输出为www.site.com/properties/en/all/all/all/316/properties/en/all/all/all/316

我已将 web/config 设置为

    <?xml version="1.0" encoding="UTF-8"?>  
<configuration>  
<system.webServer>
    <directoryBrowse enabled="false" />
    <urlCompression doStaticCompression="true" doDynamicCompression="true" />
    <rewrite>
      <rules>
<rule name="Property list URL rewrite">
   <match url="^property/([_0-9a-z-]+)/([_0-9a-z-]+)/budget-range-([_0-9a-z-]+)/([_0-9a-z-]+)/([_0-9a-z-]+)" />
<action type="Rewrite" url="resultsproperty.cfm?lang={R:1}&amp;categoryid={R:2}&amp;budegtid={R:3}&amp;typeid={R:4}&amp;propertyid={R:5}" appendQueryString="false" />
</rule>
</rules>
    </rewrite>
        <httpErrors errorMode="Detailed" />
  </system.webServer>
</configuration>

ColdFusion cfquery 如下...

<cfquery name="getProps" datasource="#session.odbcname#">
SELECT  *
FROM    properties P
INNER JOIN areas A
ON      A.area_id = P.property_areaid
INNER JOIN categories C
ON      C.category_id = P.property_propcategoryid
INNER JOIN  price R
ON      R.price_id = P.property_regularity
INNER JOIN types T
ON      T.type_id = P.property_proptypeid
WHERE   P.property_status != 'Off Market'
<cfif url.ref is not "all">
    AND     
        (
        property_ref like <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
        OR property_refid like  <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
        OR property_town like  <cfqueryparam cfsqltype="cf_sql_varchar" value="%#url.ref#%">
        )
</cfif>
ORDER   BY P.property_refid

似乎是先拉入实际的 URL,然后再添加重写。

非常感谢任何帮助。

【问题讨论】:

  • 这更有可能与您的 CFOUTPUT 有关。如果它们嵌套错误,它们将复制输出。即在 cfoutput “循环”中 - 显示更多 CF 代码。
  • 嗨,我现在已经更新了帖子并添加了 CF 代码。谢谢
  • url 重写不会对代码做任何事情。检查浏览器中的链接,看看您是否看到相同的 URL。如果它在检查中翻了一番,那么它与 URL 重写无关。您确定在 cfoutput 循环中没有 cfoutput 标签吗?
  • 您好,抱歉,我现在添加了正确的 URL webconfig

标签: iis url-rewriting coldfusion


【解决方案1】:

您需要以正斜杠开头的 href 以表明它来自根。 href 在浏览器中解析/解释。不以正斜杠开头告诉浏览器该 url 是相对于当前路径的。

如果您位于http://example.com/admin/ 并且有一个href logout,例如它将被解析为http://example.com/admin/logout。但是,如果您有一个 href /logout,它将解析为 'http://example.com/logout

正如您自己的回答所说,强制使用绝对路径是可行的,有时可能是首选,但有时不是。确保您了解根本问题。

【讨论】:

    【解决方案2】:

    解决了!通过在coldfusion应用程序文件中预先设置URL根,即&lt;cfset request.root = 'http://www.example.com/'&gt;,然后在链接中引用#request.root# var,它可以正确使用链接并且不会重复URL。所以这是一个冷融合问题,而不是 URL 重写问题。

    【讨论】:

      猜你喜欢
      • 2015-10-09
      • 1970-01-01
      • 2017-06-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-08-20
      • 1970-01-01
      相关资源
      最近更新 更多