网址重写HTTPS - >除某些页面之外的HTTP(IIS 7)

时间:2013-05-15 13:44:26

标签: regex iis-7 url-rewriting iis-7.5

现在只有一个页面,所有依赖项(css,jpg等)都是SSL。我创建了以下重写:

  <rule name="Not Appointment Form 4.1 SSL" enabled="true" patternSyntax="ECMAScript" stopProcessing="true">
      <match url=".*" negate="false" />
      <conditions>
          <!-- check if https is on -->
          <add input="{HTTPS}" pattern="on" />

          <!-- I'm only interested in the aspx files -->
          <add input="{PATH_TRANSLATED}" pattern=".aspx$" /> 

          <!-- anything BUT the page to be secured -->
          <add input="{PATH_INFO}" pattern="page-to-be-secured.aspx" negate="true" /> 
      </conditions>
      <action type="Redirect" url="http://mydomain{PATH_INFO}" redirectType="Permanent" />
  </rule>   

我已经尝试将网页名称放在匹配网址中(negate =“false”),但仍无效。

我已经测试了每个条件,它们都是单独工作的,但总的来说它并没有重定向到非HTTPS页面。

1 个答案:

答案 0 :(得分:2)

一种简单的方法是:

<rule name="Not Appointment Form 4.1 SSL" stopProcessing="true">
    <match url="^(.*)\.aspx$" />
    <conditions>
        <add input="{R:1}" pattern="page-to-be-secured" negate="true" />
        <add input="{HTTPS}" pattern="^ON$" />
    </conditions>
    <action type="Redirect" url="http://{HTTP_HOST}/{R:0}" />
</rule>

该规则适用于以.aspx结尾的每个请求的网址。如果与{R:1}之前的部分对应的第一个后向引用(.aspx)与page-to-be-secured不匹配,并且正在使用HTTPS,则会触发重定向。