zoukankan      html  css  js  c++  java
  • 返回404错误,转自(且歌且行)

    转自-http://www.cnblogs.com/WuYisLLQ/archive/2008/12/25/1362165.html

    HTTP404对SEO的影响

      自定义404错误页面是提供用户体验的很好的做法,但在应用过程中往往并未注意到对搜索引擎的影响,譬如:错误的服务器端配置导致返回“200”状态码或自定义404错误页面使用Meta Refresh导致返回“302”状态码。正确设置的自定义404错误页面,不仅应当能够正确地显示,同时,应该返回“404”错误代码,而不是“200”或“302”。虽然对访问的用户而言,HTTP状态码究竟是“404”还是“200”来说并没有什么区别,但对搜索引擎而言,这则是相当重要的。

    使用web.config中的customErrors来做的话并不好,因为asp.net会在返回的head头上加上302状态,即使你在自定义的404页面上设置Response.StatusCode = 404也是无法消除asp.net加的302错误。因此我的办法就是在全局错误处理Application_Error中设置并返回html代码。

    代码:

     void Application_Error(object sender, EventArgs e)
        {
            // 在出现未处理的错误时运行的代码
            Response.Clear();
            Response.StatusCode = 404;
            Response.Write("<html xmlns=\"http://www.w3.org/1999 /xhtml/><head><meta http-equiv=\"Content-Type\" content= \"text/html; charset=utf-8\" /><title>页面没有找到</title><meta http-equiv='refresh' content='4;url=http://www.bigbigwatch.com'>"
           + "<script type=\"text/javascript\">"
           + "function daoshu()"
           + "{ var djs = document.getElementById(\"daojishi\");"
           + "if(djs.innerHTML == 0){window.location.href='http://www.bigbigwatch.com';"
           + "return false;"
           + "}"
           + "djs.innerHTML = djs.innerHTML - 1;}"
           + "window.setInterval(\"daoshu()\", 1000);"
           + "<" + "/script>"
           + "</head><body><form id=\"form1\" runat=\"server\"><div style=\"margin-left: 100;\"> The error may occur:<ul><li>You find the page does not exist; </li><li>Your input is wrong; </li></ul><span id=\"daojishi\" style=\"color:Blue;font-size:x-large;\">5</span> seconds after their Jump to Home page, or if your browserdoes not support Jump, please <a href='http://www.bigbigwatch.com'>click here</a> Jump!</div></form></body></html>"
          );
            Response.End();
        }

    ie有个BUG:如果404页面大小不够521b的话会被ie的默认内容替换。

    另个需要注意的是meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\" />这个必须在title标签前,否则ie6下不能跳转。

  • 相关阅读:
    百度云如何免费扩容至2055G?
    OKR学习总结
    layui和bootstrap 对比
    使用马克飞象+印象笔记 如何简单便捷地发表博客?
    Sublime使用记录之SublimeServer插件介绍
    12.RcolorBrewer包
    11.R语言流程
    25.conda 下载安装与运用
    7、purge_haplogs 基因组去冗余
    5.MCScanX 与circos下载、安装、运用
  • 原文地址:https://www.cnblogs.com/wyxy2005/p/1370814.html
Copyright © 2011-2022 走看看