IIS 7.5 URL 重写至 HTTPS 无法完全正常工作

IIS 7.5 URL 重写至 HTTPS 无法完全正常工作

最近,我在 IIS 7.5 网络服务器上为网站安装了 SSL 证书。然后我设置了 URL 重写规则以将 HTTP 重写为 HTTPS。到目前为止,除了一件事之外,几乎所有事情都正常。如果我输入域名,然后输入 /language,例如 /en,则 URL 重写不起作用。该网站运行在 Drupal 7 上。例如,如果我转到联系页面,例如 www.domain.com/contact,则 Drupal 会将 URL 重写为 www.domain.com/language(例如 EN 或 FR 等)/contact,浏览器语言会检测到语言。我认为这个重写会导致 URL 重写规则失败或忽略 URL 请求,因此不会进行 HTTP 到 HTTPS 重定向。

但是当我第一次访问主页:www.domain.com,然后单击菜单按钮转到联系页面时,一切正常。HTTP 被重定向到 HTTPS。这是因为我认为语言重定向已经完成,因此 URL 重写模块可以处理新的 URL 重写请求。

这是我正在使用的规则,尝试了很多不同的方法,但结果都相似。

  <rule name="HTTP to HTTPS redirect" enabled="false" stopProcessing="true">
    <match url="http://(.*)" />
      <conditions>
        <add input="{HTTPS}" pattern="^OFF$" />
      </conditions>
    <action type="Redirect" redirectType="Permanent" url="https://{HTTP_HOST}/{R:1}" />
   </rule>

或者

    <rule name="HTTP to HTTPS redirect2" stopProcessing="true">
      <match url="(.*)" />
      <!-- Require SSL must be OFF in the site settings -->
      <conditions>
        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
      </conditions>
      <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}{REQUEST_URI}" />
    </rule>

相关内容