Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Default redirect for Error 404

I want to introduce a functionality in my ASP.net website that, whenever a request is received for an unknown URL on my domain, the user is redirected to my error_404.htm page in the root of the application.

For example, if the request is http://www.mydomain.com/blahblahblah

Then instead of returning the standard 404 error page, I want it to redirect the request to http://www.mydomain.com/error_404.htm

Update IIS Version 7.5 and .NET Framework Version 4

Update /blah.aspx redirects but /blah does not

like image 440
Shekhar_Pro Avatar asked Dec 19 '10 16:12

Shekhar_Pro


People also ask

How do I redirect all 404 pages?

To enable the plugin, go to Settings >> All 404 Redirect to Homepage settings page. Then set the 404 Redirection Status to Enabled. Enter the URL of your homepage in the Redirect all 404 pages to section to redirect all 404 pages to your homepage. Click on Update Options button to save the changes.

Should 404 pages redirect?

404s should not always be redirected. 404s should not be redirected globally to the home page. 404s should only be redirected to a category or parent page if that's the most relevant user experience available. It's okay to serve a 404 when the page doesn't exist anymore (crazy, I know).

How do I redirect 404 to 301?

Installing the plugin – Simple Alternatively, download the plugin and upload the contents of 404-to-301. zip to your plugins directory, which usually is /wp-content/plugins/ . Go to 404 to 301 tab on your admin menus. Configure the plugin options with available settings.


1 Answers

This is how you configure a custom 404 error page for both ASP.NET and non-ASP.NET requests:

<configuration>     <system.web>       <compilation targetFramework="4.0" />        <customErrors mode="On" redirectMode="ResponseRewrite">          <error statusCode="404" redirect="http404.aspx" />       </customErrors>    </system.web>     <system.webServer>       <httpErrors errorMode="Custom">          <remove statusCode="404"/>          <error statusCode="404" path="/http404.aspx" responseMode="ExecuteURL"/>       </httpErrors>    </system.webServer>  </configuration> 

As others already pointed out, you should not use an HTTP redirection to send the user to the home page, this is not only confusing to users but also to machines (e.g. search engines). It is important to use the 404 status code and not a 3xx code.

You can achieve the desired functionality using meta refresh on HTML:

<%@ Page Language="C#" %>  <html xmlns="http://www.w3.org/1999/xhtml"> <head>    <title>Not Found</title>    <meta http-equiv="refresh" content="5;url=/"/> </head> <body>    <h1>Not Found</h1>    <p>Redirecting to Home...</p> </body> </html> 
like image 95
Max Toro Avatar answered Sep 26 '22 10:09

Max Toro