【问题标题】:How to convert 404 error code in 301 permanent redirect如何在 301 永久重定向中转换 404 错误代码
【发布时间】:2012-06-06 19:43:11
【问题描述】:

我想将我的 404 状态代码转换为 301。我在 SEO 中有顶级索引网站,如果机器人没有找到我的页面,我不想失去我的位置。 对于某些 URL,我得到 404 状态,并且通过重定向到具有 404 状态代码的另一个页面对 SEO 来说不是一件好事。 所以我想将状态代码转换为 301,这样它就不会影响我的索引。 我想在它给出 404 时设置 301 状态码。我的网站在 asp.net 1.1 中,我之前尝试过很多解决方案。 一些解决方案给我 301 而不是 404 状态码,但它们在第二步中给出。意味着首先他们给 302 然后他们给 301。但我不想那样做。我想直接从 404 到 301。 用 asp.net 1.1 和 IIS 可以吗?

请帮帮我。

谢谢

【问题讨论】:

    标签: asp.net iis http-status-code-404 http-status-code-301


    【解决方案1】:

    您可以使用应用程序的 web.config 配置错误重定向。这是一个例子:

    <customErrors mode="On" defaultRedirect="~/somecatchallpage.aspx?type=error">
        <error statusCode="404" redirect="somecatchallpage.aspx?type=404"/>
        <error statusCode="301" redirect="somecatchallpage.aspx?type=301"/>
    </customErrors>
    

    这里有一些额外的阅读(对于 asp.net 1.1 版):customErrors Element

    【讨论】:

    • 感谢您的回复,但我不想要这种类型的重定向。我已经用过这个了。我已经提到我想将 404 转换为 301。这意味着当我得到 404 并重定向到某个页面时,我应该在该页面上得到 301 状态代码。通过这样做,你所建议的我会得到 302 而我不想要它。 :)
    • 有什么答案或进展吗?
    【解决方案2】:

    你用 global.asax 试过了吗?

    void Application_Error(object sender, EventArgs e) 
    {
        Exception exception = Server.GetLastError();
    
        if (exception is HttpException)
        {
            Response.Redirect(..);
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-12-02
      • 2014-09-24
      • 2013-07-17
      • 1970-01-01
      • 1970-01-01
      • 2011-11-13
      • 1970-01-01
      相关资源
      最近更新 更多