【问题标题】:URL rewrite web.config with location httpsURL 用位置 https 重写 web.config
【发布时间】:2017-05-11 02:30:22
【问题描述】:

我想将我的 Extranet 网站重定向到 https 我有以下 web.config 规则:

 <location path="." inheritInChildApplications="false">
  <system.webServer>
    <rewrite>
      <rules>

      <rule name="Redirect to https" stopProcessing="true">
       <match url="(.*)" />
        <conditions>
         <add input="{HTTPS}" pattern="off" `enter code here`ignoreCase="true" />
        </conditions>
       <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" 
                  redirectType="Permanent" appendQueryString="false" />
      </rule>
     </rules>
   </rewrite>
  </system.webServer>
</location>

问题出现是因为我的服务器上托管了几个子服务,我不希望它们也重定向,我只想重定向站点而不是服务。

【问题讨论】:

    标签: http https url-rewrite-module


    【解决方案1】:

    执行此操作的一种方法是默认重定向到 HTTPS,指定的文件夹列表除外。在以下示例中,文件夹 /service1//service2/ 被排除在重定向之外。其他一切都转到 HTTPS。

    <system.webServer>
        <rewrite>
            <rules>
                <rule name="Redirect to https" stopProcessing="true">
                    <match url=".*" />
                    <conditions>
                        <add input="{HTTPS}" pattern="off" ignoreCase="true" />
                        <!-- avoid redirection for the following paths -->
                        <add input="{PATH_INFO}" pattern="^/service1/" ignoreCase="true" negate="true" />
                        <add input="{PATH_INFO}" pattern="^/service2/" ignoreCase="true" negate="true" />
                    </conditions>
                    <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
                </rule>
            </rules>
        </rewrite>
    </system.webServer>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-13
      • 1970-01-01
      • 1970-01-01
      • 2018-06-30
      • 2012-12-06
      • 2013-02-02
      • 2014-06-13
      相关资源
      最近更新 更多