301重定向

时间:2022-05-04
本文章向大家介绍301重定向,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

301错误主要是域名更换后,搜索引擎还在使用你原有的域名地址访问你的网站,如果搜索引擎爬取的时候得到的是一个301错误,那么搜索引擎就知道你已经更换了域名,下次就会使用新域名来索引你的网站,当然你要告诉搜索引擎你的新域名是什么

【引用度娘】

//需要在webconfig配置
 <system.webServer>
    <handlers>
      <add name="301html" path="*.html" verb="*" type="System.Web.UI.PageHandlerFactory" resourceType="Unspecified" preCondition="integratedMode" />
   
    </handlers> </system.webServer>

//修改Global.asax文件

  void Application_BeginRequest(object sender, EventArgs e)
    {
        if (HttpContext.Current.Request.RawUrl.Contains("123.html"))//旧页面
        {
            Response.StatusCode = 301;
            Response.Redirect("http://www.baidu.com");//跳转地址
            Response.End();
        }
    }
    

上面的方式似乎不对,是以前的下面是 新的可用站长工具测试 返回的状态码

   string url = "http://www.baidu.com/";
   Response.StatusCode = 301;
   Response.AppendHeader("Location", url); //这个才是重点