通过web.config中的URL重写强制HTTPS

时间:2014-04-15 06:46:55

标签: iis azure url-rewriting web-config

我正在尝试通过web.config URL重写规则强制HTTPS为包含路径的URL。

例如,http://my.domain.com/folder必须强制使用https://my.domain.com/folder

我还想在其相对路径上为所有页面强制使用HTTPS

例如http:// my.domain.com/folder/page.aspx强制使用https:// my.domain.com/folder/page.aspx

这就是我所拥有的:

<rewrite>
    <rules>
      <rule name="Redirect to https">
        <match url="(.*)"/>
        <conditions>
          <add input="{HTTPS}" pattern="Off"/>
          <add input=”{REQUEST_METHOD}” pattern=”^get$|^head$” />
        </conditions>
        <action type="Redirect" url="https://{HTTP_HOST}/{R:1}"/>
      </rule>
    </rules>
  </rewrite>

2 个答案:

答案 0 :(得分:0)

检查您的外壳和您使用的报价类型。此外,第二个输入法无效 - 模式无效正则表达式。此规则适用于您想要的内容:

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

答案 1 :(得分:0)

尝试此网址重写规则:

stripe_customer_id