我有一个站点设置来使用 SSL 证书并通过 https 为站点提供服务。但是,我无法让 URL Rewrite 正常工作以重定向尝试的连接尝试以遵循某些规则,这些规则最终会导致使用特定的 url。
此时出于安全原因,我只说域名是:example.com
我正在尝试做的是以下内容。
- 所有重写都应将基本请求重写为 https://www.example.com/
例如,假设我有这些之前/之后:
- 之前:http://example.com/
- 之后:https://www.example.com/
- 之前:http://example.com/hello/
- 之后:https://www.example.com/hello/
- 之前:http://sub.example.com/
- 之后:https://sub.example.com/
等等。但是,无论我使用什么示例,我都可以在网上找到执行 HTTP 到 HTTPS 重定向的方法,IIS 只会导致无限循环重定向并且永远无法正常工作。
网站在IIS中的绑定(bind)如下:
- 类型:http/主机名:www.example.com/端口:80/IP 地址:*
- 类型:http/主机名:example.com/端口:80/IP 地址:*
- 类型:https/主机名:www.example.com/端口:443/IP 地址:*
最佳答案
我用的是这个
<rewrite>
<rules>
<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="Found" />
</rule>
</rules>
</rewrite>
关于ssl - IIS 将 HTTP 重定向到 HTTPS 重定向循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45602149/