【问题标题】:Rewriting URLs from http:// to https:// in IIS8在 IIS8 中将 URL 从 http:// 重写为 https://
【发布时间】:2015-02-11 01:03:34
【问题描述】:

目标:我想将多个子域(例如http://xxx.domain.com)重定向到https://xxx.domain.com

我在 IIS 中有以下绑定

主机名:domain.com 端口:80 IP地址:*

主机名:domain.com 端口:443 IP地址:*

我的 web.config 中有以下重写规则

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

由于某种原因http://xxx.domain.com 给出了 404 而不是被重定向。 https://xxx.domain.com 工作正常。

知道为什么http://xxx.domain.com 会给出 404 吗?

【问题讨论】:

  • 您找到解决方案了吗?我也面临这个问题,我在 web.config 中进行了所有更改,但仍然没有重定向。

标签: url-rewriting web-config rewrite iis-8


【解决方案1】:

我的 web.config 包含:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
   <system.webServer>
      <rewrite>
         <rules>
            <rule name="Redirect to HTTPS" enabled="true" stopProcessing="true">
               <match url="(.*)" />
               <conditions>
                  <add input="{HTTPS}" pattern="^OFF$" />
               </conditions>
               <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" />
            </rule>
         </rules>
      </rewrite>
   </system.webServer>
</configuration>

这对我有用。我看到的和你的区别是: 我的规则中有 "enabled="true",我的初始匹配在模式中没有 "http://",只有 "(.*)"。

【讨论】:

    【解决方案2】:

    你的匹配标签中的网址错误,应该是:

    <match url=".*" />
    

    在操作 URL 中,将 {R:1} 替换为 {R:0}

    【讨论】:

      猜你喜欢
      • 2010-12-04
      • 2014-09-20
      • 2014-07-18
      • 2011-06-02
      • 1970-01-01
      • 2021-12-28
      • 1970-01-01
      • 2012-07-23
      • 2014-12-09
      相关资源
      最近更新 更多