0

我刚刚在我的服务器上安装了 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上。我该怎么做?我想,我只需要弄清楚除了注册和登录页面之外的任何东西的正则表达式?那会是什么样的?我不精通正则表达式。

4

1 回答 1

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>
于 2012-07-26T13:49:00.103 回答