Custom 404.asp error page
This script is an example of how to use a custom 404 error page to parse imaginary, virtual, ghost folder urls and then send visitors to actual corresponding folders. For instance, if you have a folder of community user's home pages that has a URL such as http://thequarterhorse.net/members/username/ you can use http://thequarterhorse.net/username as a shortcut URL without having to actually create the folder.
Copy and paste the code below into notepad. Replace the URL and other variables with your own. You will also need to replace the number 35 with the number of characters of your own Request.ServerVariables("QUERY_STRING") which may look something like 404;http://thequarterhorse.net/pageyoucantfind but minus everything after the third slash: 404;http://www.thequarterhorse.net/ - in other words, I counted the characters in 404;http://www.thequarterhorse.net/ to get the number 35. This is the way it works on ReadyHosting.com; your server may be different?
|
| <% OPTION EXPLICIT response.status = "404 Not Found" %> <% dim strF strF = Request.ServerVariables("QUERY_STRING") %> <% dim strFileName, str3, str3b, strExt,intHowLong,strFolder strFileName = strF 'Getting the filename from our database and setting the string contents. intHowLong = Len(strFileName) 'Getting the number of character contained within the filename. if request.servervariables("SERVER_NAME")="www.YourSiteURLdotcom" then replace strF, "404;http://www.", "" str3b = intHowLong - 35 else replace strF, "404;http://", "" str3b = intHowLong - 31 end if strFolder = Right(strFilename, str3b) %><% Dim myFSO 'this line creates an instance of the File Scripting Object named myFSO SET myFSO = Server.CreateObject("Scripting.FileSystemObject") 'error handling here to make sure that things go smoothly 'if the folder does not exist If NOT myFSO.FolderExists("D:\html\users\youraccountfolder\html\members\"&strFolder) Then Response.write("<html>" & vbNewline) Response.write("<head>" & vbNewline) Response.write("<meta http-equiv=""Content-Language"" content=""en-us"">" & vbNewline) Response.write("<meta http-equiv=""Content-Type"" content=""text/html; charset=windows-1252"">" & vbNewline) Response.write("<title>The Quarter Horse Net page not found for quarter horses</title>" & vbNewline) Response.write("</head>" & vbNewline) Response.write("<body background=""http://yoursiteurl_com/images/qhdnetcanves.jpg"" leftmargin=""200"">" & vbNewline) Response.write("<h2><font color=""#466530"" face=""Verdana"">Your Site Title</font></h2>" & vbNewline) Response.write("<p><font face=""Verdana"">I'm sorry, I can't find the page you requested:</font></p>" & vbNewline) Response.write("<p><b><font face=""Verdana"">" & strFolder &"</b><BR>" & vbNewline) Response.write("<p><font face=""Verdana"">To return to my home page and site directory, click here:" & vbNewline) Response.write("<a href=""http://www.YourSiteURL/default.asp"">" & vbNewline) Response.write("www.YourSiteURL/default.asp</a> </font></p>" & vbNewline) Response.write("</body>" & vbNewline) Response.write("</html>" & vbNewline) Else Response.redirect("http://YourSiteURLdotcom/members/"&strFolder)&"" End If 'this line destroys the instance of the File Scripting Object named myFSO SET myFSO = NOTHING %> |