301重定向无法正常工作

时间:2016-10-04 06:25:24

标签: asp.net-mvc asp.net-mvc-4 redirect web-config

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

确定。我删除了我的https www.domain / - 版本,并验证了http www.domain / - 版本(没有" s")......它有效!但! 我的seo工具(seositecheckup,woorank ......) - 说,我没有301重定向.. 怎么可能? 当我验证http版本时 - 它有效,但工具没有看到变化。 当我验证所有4个版本(2(http和https)与www和2没有www) - 它可以工作,但工具也没有看到theese的变化。 当我验证https版本时 - 搜索消费者不允许我设置我的首选域,通过给我这个错误:设置首选域的过程的一部分是验证您拥有http www.domain。请验证http www.domain

以下是我在web config上的代码:

<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>

请帮忙!

1 个答案:

答案 0 :(得分:0)

<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>

试试此代码