如何404(不良网址)重定向到主页 [英] how to redirect 404 (bad urls) to the homepage

查看:272
本文介绍了如何404(不良网址)重定向到主页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用asp.net,当我(在浏览器中)手动键入URL有它给了我:

<块引用>资源无法找到。
说明:HTTP 404。您正在寻找(或它的一个依赖)可能已被删除的资源,更名或暂时不可用。请检查以下URL并确保其拼写正确。

我想一个坏的URL不存在被重新定向到主页

我如何做到这一点?我使用的地图。


解决方案

如果你没有让使用的意图知道他们将被重定向你可以只打开自定义错误,做这样的事情:

 &LT;结构&gt;
  &LT;&的System.Web GT;
    &LT;的customErrors的defaultRedirect =的Default.aspx模式=ON&GT;
      &LT;错误状态code =404重定向=的Default.aspx/&GT;
    &LT; /&的customErrors GT;
  &LT; /system.web>
&LT; /结构&gt;

I am using asp.net and when I type a bad url manually(in the browser) it gives me:

The resource cannot be found. Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.

I want a bad url that doesn't exist to be re-directed to the home page.

How do I do this? I am using sitemap.

解决方案

If you have no intentions of letting the use know they are being redirected you could just turn custom errors on and do something like this:

 <configuration>
  <system.web>
    <customErrors defaultRedirect="default.aspx" mode="On">
      <error statusCode="404" redirect="default.aspx"/>
    </customErrors>
  </system.web>
</configuration>

这篇关于如何404(不良网址)重定向到主页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆