在IIS中从非www重定向到www以及从HTTP重定向到https

问题描述 投票:0回答:1

我正在尝试从非www站点重定向到www,也从http重定向到https。

HTTP到https的效果很好,但非www到www则显示找不到页面错误。

这是我的配置:

         <rules>
            <clear />
            <rule name="non-www to www" stopProcessing="true">
                <match url="(.*)" />
                <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                    <add input="{HTTP_HOST}" pattern="^mydomain.com$" />
                </conditions>
                <action type="Rewrite" url="https://www.{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
            </rule>
            <rule name="http to https" patternSyntax="Wildcard" stopProcessing="true">
                <match url="*" />
                <conditions logicalGrouping="MatchAny" trackAllCaptures="false">
                    <add input="{HTTPS}" pattern="OFF" />
                </conditions>
                <action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" appendQueryString="false" />
            </rule>
        </rules>

发生了什么事?我已经尝试了几种非www到www的变体,所有变体都是在google中找到的网站,但是没有用。

Jaime

redirect url-rewriting iis-8
1个回答
0
投票

从评论中复制并提供更多解释。

该操作应设置为Redirect而不是Rewrite,因为您确实希望搜索引擎显示www链接,然后您的网站必须向其漫游器发出301重定向。

即使您有时需要Rewriteurl也必须是指向同一站点的相对路径。如果要重写到另一个站点(如上面使用的站点),则代理模式需要ARR。否则,IIS自然会返回404错误。

但是,重写不会更改浏览器地址栏中的URL,因此,它也不会对搜索引擎机器人产生影响。

Reference

© www.soinside.com 2019 - 2024. All rights reserved.