【发布时间】:2017-08-09 15:21:51
【问题描述】:
环境:
- Windows Server 2012 R2
- IIS 8.5
挑战
重写规则是全新的,我需要实现一个规则来做两件事:
- 将协议从 http 更改为 https
- 将主机名更改为 www.example.com
问题是我不能真正测试这个本身,因为我们的 SSL 证书只存在于我们的生产站点上,所以我需要确保我做对了。
在进行研究时,我发现有关重写规则的文档有些稀疏,但从各种示例等中拼凑出以下内容:
<rule name=”http_to_https_redirect">
<match url="(.*)" />
<conditions><add input="{HTTPS}" pattern="^OFF$" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://www.example.com/{R:1}" redirectType="Permanent" />
</rule>
我仍然不知道 {R:1} 的含义或它的行为方式,因为我发现只有一个简短的说明,它是“对规则模式的反向引用由 {R:N} 标识,其中 N 是从 0 到 9。请注意,对于这两种类型的反向引用,{R:0} 和 {C:0} 将包含匹配的字符串。” (来自:https://www.iis.net/learn/extensions/url-rewrite-module/url-rewrite-module-configuration-reference)
问题:
根据上面的第 1 点和第 2 点,上述规则是否正确?
希望有更多经验的人可以确认 - 是/否?
还发现了这个帖子: IIS Url Rewrite rule HTTP to HTTPS AND add WWW ...但实际的重写规则从未在答案中发布!
【问题讨论】:
标签: iis url-rewriting