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?

Rated:
by Aspin.com users
What do you think?

 

 

 

 




<% 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

%>
 

ASP Examples Menu of Active Server Pages scripts code Classic ASP

Classic ASP Active Server Pages Examples, code, tutorials, scriptsASP Examples Menu (below*)



Active Server Pages | ASP | Scripts | Tutorials | Code | Web Programming | Examples
Active Server Pages ASP code examples, tutorials, and snippets for use in Programming interactive websites.

NOTE: Recently changed hosting and url so some demos aren't working now because I haven't updated pathing; if you find omissions or errors let me know.
 

*

Multiple records per row with paging

Display multiple records per row

Get ID of newly inserted record, Classic ASP, Access Database

Javascript timer with ASP to keep track of time expired until login expires / timeout session is up

Multiple Javascript event functions triggered from single form onsubmit

Get Querystring key names along with querystring variables

ASP Youtube Downloader  Version FOUR
All ASP code. Allows user client side downloads of Youtube videos. You have the option to allow files to be saved directly to your site also.

ASP/PHP video downloader (Works better than ASP for large files)

Use ASP to dynamically parse a Youtube XML playlist to render to html.

Zip up an archive file of your site for backup if you need to restore website with ASP and free Zip Component.

Zip all files in a folder into an archive or backup file dynamically by specific file extension.

Sanitize or clean price cost field for database insertion or display.

Javascript image dimensions and image file size preview.

Put recordset into array, assign keys to the records then use record associated with specific array key as a variable elsewhere.

Access Database Interface Generator Wizard to read your table and field names and to create a table display.

Combining dropdown selection box menu with dynamic ASP database page.

How to redirect user to original page they tried to view before logging, after they are logged in.

Previous/Current/Next Records, or Buddy Ring Script

Custom ASP 404 page not found error script sends visitors to virtual folders

ASP Example: Combine ASP with Javascript for popup windows
dynamically sized to image dimensions.

ASP Example: How to use ASPJPEG to create thumbnails
Click for free Highly recommended thumbnailer for which you don't need Server access

ASPjpeg: How to re-scale aspect ratio of thumbnails by height instead of width.

ASP Example: What if your host has an older version of ASPJPEG that doesn't support gifs?

Using inline frames as "dynamic includes" (offline for updating)

Select Count Distinct Records for Access Database

Upload Image to folder and insert filename into database

Get date in such a way that it can be made part of a file name

Isolate a file name away from its path or extension or strip a path from a file name or strip characters from database field

User-customized on-the-fly stylesheet css files

Enhanced Page Hits Counter (also counts downloads and menu link hits)

Loop through array and compare to string with select case

Aphabetical Paging for your ASP scripts

Web Wiz Guide's Site Searcher Script modified as a file content indexer

Let Users Select How Many Records to View

Access Database for your PayPal IPN scripts

Miscellaneous collected code

You don't have to be a genius, just persistent, to write original Active Server Pages scripts

Software Recommendation: bare_bones_no_bells_and_whistles_asp_code_generator_database_interface_maker

--Lil at gmail.com