如何使用IIS将https://domain.comredirect到https://www.domain.com?

我有一个301redirecthttp://domain.com到http://www.domain.com ( http://www.domain.com $ S $ Q),但如果我浏览到http s :// domain.com我得到一个SSL错误(因为它期望www.domain.com)。

在浏览器抛出一个证书错误之前,有没有办法使它redirect?

是的,但不是你的想法。

  • 您将需要有效的domain.com证书
  • 你将需要domain.com和www.domain.com分开的公共IP地址

如果你不能这样做,不幸的是,你运气不好。 您不能使用HOST头来区分这两个请求,因为这太晚了(因此,分开的IP地址)。 除非你有一个有效的证书,否则浏览器将会窒息,所以你还需要第二个证书。

恐怕没有办法解决这些要求。

我有完全相同的要求,如redirect所有的https://domain.com到https://www.domain.com ,也redirect所有HTTP到HTTPS,在这里,我如何实现,并得到它的工作IIS 8.5。 我在web.config文件中使用了以下代码:

<system.webServer> <!--Maybe some other settings--> <rewrite> <rules> <rule name="http 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> <rule name="Redirect to www" patternSyntax="Wildcard" stopProcessing="true"> <match url="*" /> <conditions> <add input="{HTTP_HOST}" pattern="yourdomainname.com" /> </conditions> <action type="Redirect" url="https://www.yourdomainname.com/{R:0}" /> </rule> </rules> </rewrite> <!--Maybe some other settings--> </system.webServer> 

这工作像魅力。 其实我通过使用Web平台安装程序安装“URL重写模块”在web.config中生成以上代码。 安装后,我在IIS 8.5中find了这个模块,然后我添加了新的规则。 希望你可以直接在web.config中写这段代码来完成任务。

有一个方法。 您可以获得www.domain.com和domain.com的单一证书。 然后你可以使用一个常规的redirect。 这些多域证书通常比较昂贵。