Thanks for the idea!  I forgot about taking the "back door" to solve this
problem, and this actually kills 2 (or more) birds with 1 stone since I can
use this as a redirect lookup for all of the apps/domains hosted on this
server.

If anyone else needs something like this, here is my VERY alpha code,
ugliness and all.  It's pretty rough and just uses an Access database for
the lookups; final version will be code-tweaked and will use Oracle.  New
404's are added automatically, and the idea would be that an administrator
goes through periodically (via an admin interface to the database), figures
out which 404's are because of fatfingering/misspellings, and which ones are
looking for "lost" pages, and from there a forwarding URL can be added to
complete the redirect:

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>
<head>
 <title>Databased Redirects</title>
</head>

<body>
<!--- Initialize tmp.* variables --->
<cfparam name="tmp.query_string" type="string" default="">
<cfparam name="tmp.badURL" type="string" default="">

<!--- Set the tmp.query_string value --->
<cfset tmp.query_string = "?" & #CGI.query_string#>

<!--- Set the tmp.badURL value --->
<cfset tmp.badURL = "http://"; & #CGI.server_name# & #CGI.script_name#>

<!--- If the value of tmp.query_string >1, create the new tmp.badURL with
the query string --->
<cfif len(trim(tmp.query_string)) GT 1><cfset tmp.badURL = #tmp.badURL# &
#tmp.query_string#></cfif>

<!--- Check to see if the bad URL is in the database --->
<cfquery name="checkURL"
datasource="c:\inetpub\wwwroot\redirect\redirect.mdb" dbtype="OLEDB"
provider="Microsoft.Jet.OLEDB.4.0"
providerdsn="c:\inetpub\wwwroot\redirect\redirect.mdb" username="admin"
password="">
 SELECT badURL, goodURL
 FROM tblRedirect
 WHERE tblRedirect.badURL LIKE '#tmp.badURL#'
</cfquery>

<cfif checkURL.recordcount GT 0>
 <!--- If this is not the first time the bad URL is encountered, it will be
in the database. --->
 <!--- *** debug ***
 <cfoutput query="checkURL">#badURL#, #goodURL#</cfoutput><hr> --->

 <!--- This works, and changes the URL. Make sure there is a value set for
goodURL, otherwise it will loop. --->
 <cfif len(trim(checkurl.goodurl)) GT 0>
  <cfoutput><meta http-equiv="refresh" content="0;
url=#checkURL.goodURL#"></cfoutput>
 </cfif>

<cfelse>
 <!--- If this is the first time the bad URL is encountered, save it to the
database. --->
 <cfquery name="addBadURL"
datasource="c:\inetpub\wwwroot\redirect\redirect.mdb" dbtype="OLEDB"
provider="Microsoft.Jet.OLEDB.4.0"
providerdsn="c:\inetpub\wwwroot\redirect\redirect.mdb" username="admin"
password="">
  INSERT INTO tblRedirect(badURL,http_referer,remote_addr)
  Values('#tmp.BadURL#', '#CGI.http_referer#', '#CGI.remote_addr#')
 </cfquery>
</cfif>


<h1>File not found</h1>

<!--- *** debug ***
<cfoutput>#checkURL.recordCount#</cfoutput>
404 page.
<cfoutput>#tmp.badURL#</cfoutput>
<hr>
<cfoutput>http://#CGI.server_name##CGI.script_name#</cfoutput>
 *** /debug *** --->

</body>
</html>

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

----- Original Message -----
From: "Matt Robertson" <[EMAIL PROTECTED]>
To: "CF-Talk" <[EMAIL PROTECTED]>
Sent: Monday, May 20, 2002 12:36 PM
Subject: RE: CF Error pages and redirects for 404 pages


> Can you put in a site-wide error handler in CF admin?  If so that would
> let you code in pretty much anything you want.  I just reroute to the
> current domain's index.cfm, but there's no reason you couldn't do
> something more complex/useful.
>
> --Matt Robertson--
> MSB Designs, Inc.
> http://mysecretbase.com
>
>
>
> -----Original Message-----
> From: Pete Ruckelshaus [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 20, 2002 8:43 AM
> To: CF-Talk
> Subject: CF Error pages and redirects for 404 pages
>
>
> Hi,
>
> My "challenge of the week" is to provide automated forwarding services
> to URL's that return a "File not found" 404 error.  This would act as a
> sort of "switchboard" that, whenever a 404 error was encountered, a
> query would be run against a database for the requested URL, and if
> there were a "new" URL value for that originally requested page, the
> user would be redirected there without ever seeing the actual 404 page.
>
> Now, in theory, this is how it would work:
>
> * Create a database table that holds the values for "old" URL's and the
> "good" URL's that the old URL's should redirect to
> * Create a custom 404 page that executes a query of this table each time
> it's (the custom 404 page) executed.  The logic would be something like
> this...
>   - run query, querying for the "bad" URL value and returning the "good"
> URL value
>   - If a value is returned,
>      + do a cflocation to the new URL
>   - If a value is not returned
>      + display the 404 page
>
> So, here's the first problem I'm running into.  I have the following set
> in my application.cfm: <cfapplication name="redirect_test"> <cferror
> type="request" template="404.cfm">
>
> Yet, 404.cfm is not displayed; the standard IIS error page is displayed.
> Also, it's documented that request error pages can't have any CF code in
> them.  Am I doing something wrong?  Am I missing something?  Is there
> any way to accomplish what I need to do?
>
> Thanks
>
> Pete
>
>
> 
______________________________________________________________________
This list and all House of Fusion resources hosted by CFHosting.com. The place for 
dependable ColdFusion Hosting.
FAQ: http://www.thenetprofits.co.uk/coldfusion/faq
Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to