Redirect IIS 7中HTTP和HTTPS的域重写

Redirect IIS 7中HTTP和HTTPS的域重写,redirect,iis-7,web-config,rewrite,isapi-rewrite,Redirect,Iis 7,Web Config,Rewrite,Isapi Rewrite,我想在一个请求中执行多个301重定向,我发现这很有帮助。然而,我有一个问题在哪里http://example.com 重定向到https://www.example.com 但是https://example.com 不重定向到https://www.example.com 下面是我的例子: SEO-remove default.aspx工作正常,但没有HTTPS => 但是=> 搜索引擎优化-删除尾随斜杠不起作用,没有如上所述的HTTPS 所有链接都会得到尾随斜杠 => => SEO-To

我想在一个请求中执行多个301重定向,我发现这很有帮助。然而,我有一个问题在哪里http://example.com 重定向到https://www.example.com 但是https://example.com 不重定向到https://www.example.com

下面是我的例子:

SEO-remove default.aspx工作正常,但没有HTTPS => 但是=>

搜索引擎优化-删除尾随斜杠不起作用,没有如上所述的HTTPS 所有链接都会得到尾随斜杠 => =>

SEO-ToLower工作正常,但没有上面提到的HTTPS => =>

SEO-http规范重定向100%有效 =>

SEO-https规范重定向根本不起作用 =>-失败

SEO-非规范重定向无法100%工作。如果没有这个规则,样式表将无法加载,但是与上面任何一个都不匹配的其他链接也不会被加载 => => => =>

这就是我所实现的,问题如上所述

<rewrite>
    <rules>
        <clear />
        <rule name="WhiteList - resources" stopProcessing="true">
            <match url="^resources/" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false" />
            <action type="None" />
        </rule>
        <rule name="SEO - remove default.aspx" stopProcessing="false">
            <match url="(.*?)/?default\.aspx$" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_METHOD}" pattern="GET" />
            </conditions>
            <action type="Rewrite" url="_{R:1}" />
        </rule>
        <rule name="SEO - Remove trailing slash" stopProcessing="false">
            <match url="(.+)/$" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_METHOD}" pattern="GET" />
               <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
                <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            </conditions>
            <action type="Rewrite" url="_{R:1}" />
        </rule>
        <rule name="SEO - ToLower" stopProcessing="false">
            <match url="(.*)" ignoreCase="false" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_METHOD}" pattern="GET" />
                <add input="{R:1}" pattern="[A-Z]" ignoreCase="false" />
            </conditions>
            <action type="Rewrite" url="_{ToLower:{R:1}}" />
        </rule>
        <rule name="SEO - http canonical redirect" stopProcessing="true">
            <match url="^(_*)(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_HOST}" matchType="Pattern" pattern="^www\.example\.com$" ignoreCase="true" negate="true" />
                <add input="{HTTP_METHOD}" pattern="GET" />
            </conditions>
            <action type="Redirect" url="https://www.example.com/{R:2}" />
        </rule>
        <rule name="SEO - https canonical redirect" stopProcessing="true">
            <match url="^(_*)(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_HOST}" matchType="Pattern" pattern="^www\.example\.com$" ignoreCase="true" negate="true" />
                <add input="{HTTP_METHOD}" pattern="GET" />
                <add input="{HTTPS}" pattern="^ON$" ignoreCase="true" />
            </conditions>
            <action type="Redirect" url="https://www.example.com/{R:2}" />
        </rule>
        <rule name="SEO - non-canonical redirect" stopProcessing="true">
            <match url="^(_+)(.*)" />
            <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
                <add input="{HTTP_METHOD}" pattern="GET" />
            </conditions>
            <action type="Redirect" url="{R:2}" />
        </rule>         
    </rules>
</rewrite>

这并不是一个真正的解决方案,因为我发现了IIS的实际问题

当您使用上面的设置规则或https规范重定向进行访问时,如果您没有裸域证书,它将首先给您一个证书错误。如果用户选择继续,则将重定向到


我认为这可能发生在DNS协商级别,而不是IIS级别。

考虑在https条件之后添加ignoreCase=true:不幸的是,这没有帮助。我今天早上试过了。只需添加一个映射到裸域端口443和任何证书,然后重定向到正确的www-domain-web.config。用户不会收到错误的证书错误,因为浏览器将在打开页面之前重定向到正确的url。