URL重写:服务器不重写

时间:2011-01-31 19:22:01

标签: iis-7 url-rewriting

我正在尝试使用URL重写模块在IIS 7.0服务器中重写URL,但它无效。

我必须构建一个规则,用于从第3部分的身份验证页面接收带有“; jsessionid = null”令牌的URL,该令牌在调用我的页面时会在IIS中引发错误。我试图只删除“; jsessionid = null”语句。我需要URL查询语句到我的应用程序(preceeding question)。

我写了这条规则:

模式:

(http://.*);jsessionid=null(.*)

动作:

{R:1}{R:2}

当我测试模式时,结果是OK。但在实践中,没有任何事情发生,就像没有重写模块一样。在Web.config文件中似乎没问题:

  <system.webServer>
      <modules runAllManagedModulesForAllRequests="true" />
        <rewrite>
            <rules>
                <rule name="refazer_url_autenticador_df" enabled="true" patternSyntax="ECMAScript" stopProcessing="false">
                    <match url="(http://.*);jsessionid=null(.*)" />
                    <action type="Rewrite" url="{R:1}{R:2}" logRewrittenUrl="true" />
                </rule>
            </rules>
        </rewrite>
  </system.webServer>

当令牌在URL中时,IIS会引发错误:

404 - File or directory not found.

    The resource you are looking for might have been removed, had its name changed, or is temporarily unavailable.

如果没有令牌(URL手动重写),它就会好起来。

怎么了?也许是规则,也许是另一种ISS配置?

谢谢!

1 个答案:

答案 0 :(得分:2)

您应该使用失败的请求跟踪来更好地了解正在发生的事情,特别是您应该在测试模式UI中测试的实际值。请参阅:Failed Request Tracing for URL Rewrite

我猜测正在发生的事情是Match中的URL永远不会包含HTTP协议,而是从站点的根目录开始。另外,JSessionid是查询字符串的一部分吗?如果是,则需要使用条件来捕获条件中的QUERY_STRING。最后确保最终结果只包含从站点/的根目录开始的URL,而不是HTTP。仅在路由到其他服务器/应用程序池但需要在计算机中安装应用程序请求路由(ARR)时才需要这样做。