The 404.asp File

Previous Topic Previous Next Topic Next
Xoc Software

Other Xoc managed sites:
<%@ Language=VBScript %>
'404 Handler
'Written by Greg Reddick
Option Explicit

Const strXMLDoc = "/_site/404.xml"

Sub Redirector()
   Dim strRequest
   Dim strAbsUrl
   Dim dom
   Dim nod
   Dim strNew
   Dim strIp

   strRequest = Request.QueryString
   strAbsUrl = LCase(Mid(strRequest, Instr(Instr(1, strRequest, "://") + 3, strRequest, "/")))

   set dom = Server.CreateObject("msxml2.domdocument")
   dom.async = False
   dom.validateOnParse = False
   Call dom.setProperty("SelectionLanguage", "XPath")
   If dom.load(Server.MapPath(strXMLDoc)) Then
      'See if we're dealing with a spider (which we don't forward)
      strIp = Request.ServerVariables("REMOTE_ADDR")
      Set nod = dom.selectSingleNode("/descendant::ip[attribute::address='" & strIp & "']")
      If nod Is Nothing then
         'See if there is an address to forward
         Set nod = dom.selectSingleNode("/descendant::url[attribute::old='" & strAbsUrl & "']")
         If Not (nod Is Nothing) Then
            strNew = nod.attributes.getNamedItem("new").value
            Response.Status = "301 Moved Permanently"
            Call Response.AddHeader("Location", strNew)
            Call Response.Write("<html><head><title>Object moved</title></head>")
            Call Response.Write("<body><h1>Object Moved</h1>")
            Call Response.Write("This object may be found at <a href=""" _
               & strNew & """>" & strNew & "</a>.")
            Call Response.Write("</body></html>")
            Call Response.End
         End If
      End If
      Call Response.Write(XMLError(dom.parseError, strXMLDoc))
   End If
   set nod = Nothing
   Set dom = Nothing
End Sub

Function XMLError(parseError, strUrl)
   XMLError = "Error Code: " & CStr(parseError.errorCode) _
      & "<br />File Position: " & CStr(parseError.filepos) _
      & "<br />Line: " & Cstr(parseError.line) _
      & "<br />Line Position: " & Cstr(parseError.linepos) _
      & "<br />Reason: " & Server.HTMLEncode(parseError.reason) _
      & "<br />Source Text: " & Server.HTMLEncode(parseError.srcText) _
      & "<br />URL: " & Server.HTMLEncode(parseError.URL) _
      & "<br />"
End Function

Call Redirector()
Response.Status = "404 File not found"
%><?xml version="1.0" encoding="UTF-8" standalone="no" ?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
      <title>The Page Cannot be Found</title>
      <meta name="robots" content="noindex"></meta>
             FONT-FAMILY: Verdana, Arial, Helvetica, sans-serif
             COLOR: #cd5c5c
             COLOR: #cd5c5c
            WIDTH: 540px
               <h1>The Page Cannot be Found</h1>
               <hr />
                  <li>The requested file has been deleted.</li>
                  <li>The requested file has never existed.</li>
                  <li>The requested file is temporarily unavailable 
                  due to maintenance, upgrades, or other similar reasons.</li>
                  <li>The requested file has moved, and we didn't automatically
                  forward to the new page.</li>
               <hr />
               <h2>Please try the following:</h2>
                  <li>If you typed the page address into the web browser, make
                  sure that you spelled it correctly.</li>
                  <li>Open the <a href="/">home page</a> of this site.</li>
                  <li>Click the Back button to try another link.</li>
                  <li>Try <a href="/search.asp">searching</a> for
                  something related to the original topic of the page.</li>
               <hr />
               <h2>HTTP 404 - File not found</h2>