【问题标题】:Url Rewrite HTTPS -> HTTP except certain page (IIS 7)Url Rewrite HTTPS -> HTTP 除了某些页面(IIS 7)
【发布时间】:2013-05-15 23:23:04
【问题描述】:

目前只有一页和所有依赖项(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>   

我已尝试将页面名称放入匹配 url (negate="false") 中,但仍然无法正常工作。

我已经测试了每个单独的条件,它们都单独工作,但作为一个整体,它不会重定向到非 HTTPS 页面。

【问题讨论】:

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


    【解决方案1】:

    一个简单的方法是:

    <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 结尾的每个请求的网址。如果.aspx之前的部分对应的第一个反向引用({R:1})与page-to-be-secured不匹配并且正在使用HTTPS,则触发重定向。

    【讨论】:

    • 如何只为 www 执行此操作?
    • @tpbafk 添加条件&lt;add input="{HTTP_HOST}" pattern="^(www\.)(.*)$"&gt;&lt;/conditions&gt;
    猜你喜欢
    • 2012-07-23
    • 2012-10-10
    • 2014-03-19
    • 2015-12-10
    • 2013-11-01
    • 2014-03-17
    • 2015-08-31
    • 1970-01-01
    • 2012-02-28
    相关资源
    最近更新 更多