【问题标题】:IIS Url rewrite does not workIIS Url 重写不起作用
【发布时间】:2015-04-28 14:27:43
【问题描述】:

我遇到了 iis 重写模块的问题。我用谷歌搜索它并搜索它太多,但我的问题仍然存在。

我有两个重写规则,第一个将任何 http 请求重定向到 https 等效项,第二个将某些特定页面重定向到其他页面。

http 请求成功重定向到 https,但第二条规则无法正常工作。

<rewrite>
  <rules>      
    <rule name="redirect special page" stopProcessing="true">
      <match url="(.*)MySite.com/accountTransactions" />
      <action type="Redirect" url="MySite.com/404.html" />
    </rule>
    <rule name="HTTP to HTTPS redirect" stopProcessing="true">
      <match url="(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" />
    </rule>
  </rules>
</rewrite>

我使用的是 IIS 8,windows server 2012 R2。

怎么了?

【问题讨论】:

    标签: iis url-rewrite-module


    【解决方案1】:

    match url不应包含域名,而是路径

    <match url="^accountTransactions" />
    

    见http://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference

    如果您需要匹配特定域下的路径(当您的网站有多个域名时),那么您应该为 {HTTP_HOST} 添加条件

    <conditions>
       <add input="{HTTP_HOST}" type="Pattern" pattern="^www\.mysite\.com$"> 
    </conditions>
    

    【讨论】:

      猜你喜欢
      • 2013-07-26
      • 2015-01-29
      • 1970-01-01
      • 1970-01-01
      • 2012-12-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-07-20
      相关资源
      最近更新 更多