Forum Moderators: open

Message Too Old, No Replies

404 redirect page

404 page handler in ASP

         

jaydlee

4:19 pm on Feb 13, 2003 (gmt 0)



I need help on a project I'm working on. I have a 404 page on my website and i need it to be more dynamic. When a person types in a URL w/ a folder name after the domain (i.e. www.domain.com/test), I need the page to take out just the word "test". Then in my select case statement, I have a case called "test" where it will automatically redirect them to a different web address. The problem I'm having is in caputuring the original URL the person typed. Right now, it's capturing the 404 page iteself. Here is a snipet of code:

dim textlength, LastStringURL1, LastStringURL2
textlength = Len(request.ServerVariables("SCRIPT_NAME"))
LastStringURL1 = textlength - 1
LastStringURL2 = Right(request.ServerVariables("SCRIPT_NAME"),LastStringURL1)

select case LastStringURL2

case "test"
Response.Redirect("../content/TEST/test.asp")

korkus2000

1:57 pm on Feb 14, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to WebmasterWorld jaydlee,

Have you tried using the HTTP_REFERER server variable instead of script_name? I have never done it on a 404. It may give you the place they came from and not the type in. Worth a try though.

lithgo

9:10 am on Feb 24, 2003 (gmt 0)

10+ Year Member



I use Request.QueryString to capture the url in this scenario...it'll have a "404;" in front of it so will look something like "404;http://www.domain.com/test"

davemarks

8:04 pm on Mar 12, 2003 (gmt 0)

10+ Year Member



You need to look in the querystring...

This is a quick snippet of some of my code. Note this doesn't support https:// but support could be added quite easily.

thePage gives you everything from the first / onwards
theError gives you the error code, in this case 404

<%
tmpError = Request.ServerVariables("query_string")
IF tmpError <> "" THEN
intLength = (InStr(1, tmpError, "http://")) - 1
theError = Left(tmpError, intLength)
tmpPage = replace(tmpError,"404;http://","")
intLength = Len(tmpPage) - (InStr(1, tmpPage, "/")) + 1
thePage = Right(tmpPage, intLength)

strSQL = "SELECT * FROM [404] WHERE [page_url] = '" & thePage & "'"
rs.Open strSQL, conn, 1, 2
IF NOT Rs.EOF THEN
page_redirect = Rs("page_redirect")
Rs("page_hit") = Rs("page_hit") + 1
Rs.update
Rs.Close
Response.Redirect(page_redirect)
ELSE
'Add Logging in here at some point
END IF
END IF %>