在Windows Server 2012 R2中使用IIS。
我有一个网站可以通过url.com和www.url.com 。 我有https://url.com使用https://letsencrypt.org/设置。
我想把所有的input请求redirect到https://url.com/{path}也就是说,它需要处理
我将这个重写规则添加到webconfig。
<rewrite> <rules> <rule name="HTTP to HTTPS redirect" stopProcessing="true"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="off" ignoreCase="true" /> </conditions> <action type="Redirect" redirectType="Found" url="https://{HTTP_HOST}/{R:1}" /> </rule> </rules> </rewrite>
这适用于任何url,如http://url.com/some但如果我inputhttps://www.url.com/s我得到一个错误,说明连接是不安全的。 如果我尝试使用http://www.url.com ,情况也是如此
我如何做这项工作?
检查您正在使用的SSL证书中的主题名称和主题替代名称。
似乎它只适用于url.com而不适用于www.url.com
您在申请证书时需要提及这一点
您无法避免请求到达www.example.com,也不会收到错误信息,因为redirect是在SSL协商完成之后发生的,而客户端正在请求一个您没有证书的名称。
Letsencrypt允许您完美地拥有几个名字相同的证书。 所以你必须这样做,以避免客户端浏览器抱怨或证书中的名称不匹配。