IIS Url重写以将用户切换回HTTP

时间:2012-07-26 08:15:53

标签: regex iis-7 url-rewriting

我刚在服务器上安装了URL重写模块2.0。我有以下规则,如果用户导航到登录或注册视图,则会将用户从http切换到https。

<rewrite>
      <rules>
        <rule name="Redirect to SSL for login and register" stopProcessing="true">
          <match url="^login.aspx$|^register.aspx$" />
          <conditions>
            <add input="{HTTPS}" pattern="^OFF$" />
          </conditions>
          <action type="Redirect" url="https://{HTTP_Host}/{R:0}" />
        </rule>
      </rules>
    </rewrite>

这样,当用户尝试访问登录或在http上注册页面时,他将切换到相关的https页面。但是一旦用户使用https://server.com/login.aspx登录,我希望他导航回http。确切地说,我想写一条规则,除了登录和注册之外的所有页面都强制在http上。我该怎么办?我想,我只需要弄清楚注册和登录页面的正则表达式吗?那会是什么样的呢?我不熟练使用正则表达式。

1 个答案:

答案 0 :(得分:1)

怎么样:

<rewrite>
  <rules>
    <rule name="Redirect to SSL for login and register" stopProcessing="true">
      <match url="^login\.aspx$|^register\.aspx$" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
      <action type="Redirect" url="https://{HTTP_Host}/{R:0}" />
    </rule>
    <rule name="Redirect to non-SSL for others" stopProcessing="true">
      <match url="^.*$" />
      <conditions>
        <add input="{HTTPS}" pattern="^ON$" />
      </conditions>
      <action type="Redirect" url="http://{HTTP_Host}/{R:0}" />
    </rule>
  </rules>
</rewrite>