在IIS7中,有一条规则可以自动redirect到我们网站使用的HTTPS。
<rule name="Redirect to HTTPS" enabled="true" stopProcessing="false"> <match url="(.*)" /> <conditions> <add input="{HTTPS}" pattern="^OFF$" /> </conditions> <action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="SeeOther" /> </rule>
我们正在使用相同的Web应用程序添加一个新的域名(例如www.newdomain.com),但是URL的处理方式不同。 当在newdomain.com或类似地www.newdomain.com上访问时,用户应该被redirect到https://www.newdomain.com/example ,因为我们目前没有为newdomain.com提供SSL证书。 然而,我们现有的域使用一个单独的子域名比我们不需要由IIS处理。 要处理这个redirect,我使用下面的规则:
<rule name="Redirect newdomain" enabled="true" stopProcessing="false"> <match url="(^$)" /> <conditions> <add input="{HTTP_HOST}" pattern="^(www\.)?newdomain\.com$" /> </conditions> <action type="Redirect" url="https://www.newdomain.com/example" appendQueryString="true" redirectType="Permanent" /> </rule>
从www.newdomain.com访问该网站时,此规则有效。 但是,当尝试访问没有子域名的newdomain.com时,redirect仅出现在初始规则中,并且用户被定向到https://newdomain.com ,并出现ssl证书错误。 如何获得redirect来设置正确的子域,而不影响任何网站只使用其他规则?