IIS 7.5 HTTP到HTTPS重定向

问题描述 投票:1回答:2

我试图让所有HTTP请求重定向到HTTPS。这是我的web.config:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        <handlers accessPolicy="Read, Execute, Script" />
    </system.webServer>


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

</configuration>

我在Stackoverflow上的另一篇文章中找到了这个示例:How to force HTTPS using a web.config file

当我保存该文件并尝试使用http访问我的网站时,它不会重定向到https。

我想也许文件被忽略了所以我在web.config中输入了一些不正确的语法然后我得到了500错误 - 这意味着它确实在查看web.config文件。

我误解了上面的配置应该怎么做?我想将所有HTTP请求重定向到HTTPS。

正在重定向到的站点是Tomcat的虚拟目录,如果它有所不同。

web-config iis-7.5 http-redirect
2个回答
4
投票

假设您已安装URL Rewrite。 Click here for info/installation.

确保在IIS管理器中的URL重定向中配置了以下内容。

匹配网址部分

请求的URL:匹配模式 使用:正则表达式 模式:(。*)

确保选中忽略大小写 条件科

逻辑分组:全部匹配 输入:{HTTPS} 类型:匹配模式 图案:^ OFF $

行动科

操作类型:重定向

动作属性

重定向网址:https:// {HTTP_HOST} / {R:1} 确保'确认'追加查询字符串'已被选中

重定向类型:见其他(303)


1
投票

试试这个:

<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="SeeOther" />
</rule>
© www.soinside.com 2019 - 2024. All rights reserved.