PROGRAMMING » ASP

ID #1101

301 and 404 redirect

The following asp file will provide 301 redirects from specific broken links to the cooresponding correct file. It will also redirect any other requests for files that generate a 404 error to the site index.

Create a file called 404.asp in the site root and change the server 404 path to reflect this location.

/404.asp

 

<%
sname = Request.ServerVariables("QUERY_STRING")
sname = lcase(sname)

if InStr(sname,"broken-link1.html") <> 0 then
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/file1.html"

elseif InStr(sname,"broken-link2.html") <> 0 then
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/file2.html"

elseif InStr(sname,"broken-link3.html") <> 0 then
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/file3.html"

elseif InStr(sname,"broken-link4.html") <> 0 then
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/file4.html"

elseif InStr(sname,"broken-link5.html") <> 0 then
Response.Status = "301 Moved Permanently"
Response.AddHeader "Location", "http://www.domain.com/file4.html"


else
response.redirect "http://www.domain.com/"
end if
%>

Tags: -

Related entries:

Last update: 2010-09-01 22:40
Author: Admin
Revision: 1.0

TechNetSource on Facebook
| More