Custom Error-Pages and 301 redirects
Let´s assume, you´ve just acquired an expired domain and you´ve recognized that there are plenty of back links pointing to a forum, a blog or something like that. Well, the first problem is, that (in most cases) you won´t be able to use that exactly software and you may not use the formerly used content.
<error statusCode="404" redirect="404.aspx"/>
</customErrors>
In my particular case this one is already overloaded - I could have just used this one:
This way, a clean and fully functional 301 redirect for all 404-errors will be available.
301 redirect with ASP.NET
For SEO-purposes it will be good to 301-redirect the urls that have deep links, because otherwise google may penalize you because of lots of 404-errors. 2nd reason to do this is tousle the link power of all incoming links. The solution:
You may use custom 404-pages in IIS. But this one is better, in web.config in system.web just add this section:
<customErrors defaultRedirect="404.aspx"
redirectMode="ResponseRewrite" mode="On"><error statusCode="404" redirect="404.aspx"/>
</customErrors>
In my case I´ve added a "404.aspx" where I´m just redirecting via 301-redirect to the root of my domain. Now a requests gets processed like this:
- Request comes in, get´s handled by web.config and redirects (301) to 404.aspx - 301 because of redirectMode="ResponseRewrite"
- (ResponseRedirect would create a 302) 404.aspx receives the request (inculding the error-path)
- Now you can conditionally (error-path) redirect.
<customErrors defaultRedirect="~/" redirectMode="ResponseRewrite" mode="On">
<error statusCode="404" redirect="~/"/>
</customErrors>
<error statusCode="404" redirect="~/"/>
</customErrors>
This way, a clean and fully functional 301 redirect for all 404-errors will be available.
301 redirect with ASP.NET
302-Redirects are bad for search-engines, just because it is a "temporarily moved" Message, which means, that its target could change by each and every request. To pass Linklove, PageRank, Trust etc of a URL to another, you need to use a 301-redirect.
The most flexible way to do this, is to use a small code-behind snippet:
Response.Clear();
Response.StatusCode = 301;
Response.AppendHeader("location", "http://www.google.de");
Response.End();
Response.StatusCode = 301;
Response.AppendHeader("location", "http://www.google.de");
Response.End();
This way Google tranfers the trust, the linklove, the PageRank, etc to the redirect´s target
Comments