301 重定向无法正常工作

301 redirect is not working properly

我遇到了 301 重定向问题。我们有一个站点 (https://domain) 并希望为此设置首选域(非 www)- 我使用 google 分析验证了 2 个版本(https 域和 https www.domain)和 html 页。 当我选择一个首选域时 - 它给我这个错误:设置首选域的过程的一部分是验证您拥有 http www.domain/。请验证 http www.domain/.

好的。我删除了我的 https www.domain/ - 版本,并验证了 http www.domain/ - 版本(没有 "s")......它有效!但! 我的搜索引擎优化工具(seositecheckup,woorank ...) - 说,我还没有 301 重定向.. 怎么可能? 当我验证 http 版本时 - 它可以工作,但工具没有看到这些更改。 当我验证所有 4 个版本(2(http 和 https)带 www 和 2 不带 www)时 - 它有效,但工具也没有看到这些变化。 当我验证 https 版本时 - 搜索控制台不允许我设置我的首选域,给我这个错误:设置首选域的过程的一部分是验证你拥有 http www.domain。请验证 http www.domain

这是我在网络配置上的代码:

<rule name="Redirect to https" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" ignoreCase="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}{REQUEST_URI}" redirectType="Permanent" appendQueryString="false" />
</rule>
<rule name="Redirect to WWW" stopProcessing="true">
<match url=".*" />
<conditions>
<add input="{HTTP_HOST}" pattern="^domain$" />
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://domain/{R:0}"
redirectType="Permanent" />
</rule>
  </rules>
</rewrite>

求求你帮忙!

<rule name="Imported Rule 1" stopProcessing="true">
                  <match url="^(.*)$" ignoreCase="false" />
                  <conditions>
                    <add input="{HTTP_HOST}" pattern="^domain.com" ignoreCase="false" />
                  </conditions>
                  <action type="Redirect" redirectType="Permanent" url="http://www.domain.com/{R:1}" />
                </rule>

试试这个代码