Tuesday, 19 June 2012

Redirect 404 error to custom page

A 404 error message is the standard HTTP standard response code which is returned when the visitor cannot communicate with the server. This is a very common error on the web and it occurs when you are trying to visit a page which has either been deleted or has been moved somewhere else.

"A 404 error message usually looks something like this :

    Not Found

    The requested URL /index.php was not found on this server.


If a visitor comes to your site and sees a standard 404 error message it’s unlikely they will make the effort to see any part of your site. Therefore it is very important to create a 404 page on your site and redirect traffic from incorrect urls.

To do this just add the following line to "web.config" file


<system.web>

  <customErrors defaultRedirect="FileNotFound.aspx">

    <error statusCode="404" redirect="filenotfound.htm"/>

  </customErrors>

</system.web>

and create custom error page "filenotfound.htm" and "FileNotFound.aspx".

That’s all there is to it. Now when a visitor views an incorrect url on your site they will see your custom error page.

No comments:

Post a Comment