Here's the 404 redirector code that I developed for a couple of my sites:

<!---
        404 Redirector
        Query redirects table //for all active values, put in server scope.
        //Uses QoQ to get values,
         - if value is in the database, do an HTTP 301 (Moved Permanently) 
redirect.
         - if value is not in the database, do an HTTP 307 (Temporary Redirect)
         //- if value is not in the database, insert it
         //- if value is in the database but doesn't have a goodurl set,
increment the count
         + Requires datasource "redirects"
--->
<cfscript>
        attemptedURL = "http://"; & CGI.server_name & CGI.script_name;
        generatedURL = getToken(CGI.query_string, 2, ";");
        if (len(trim(generatedURL)) EQ 0) {
                generatedURL = attemptedURL;
        }
        if (findNoCase(":80", generatedurl) NEQ 0) {
                generatedurl = replacenocase(generatedurl, ":80", "");
        }
</cfscript>
<cfquery name="qryRedirect" datasource="redirects">
        SELECT          R.goodURL
        FROM            tblRedirects R
        WHERE           R.badURL = '#generatedURL#' AND
                                ((R.goodurl IS NOT NULL) OR
                                (R.goodurl != ''))
</cfquery>
<cfif qryRedirect.recordcount GT 0>
        <cfheader name="Location" value="#qryRedirect.goodurl#">
        <cfheader statuscode="301" statustext="Moved Permanently">
        <cfabort>
<cfelse>
        <cfheader name="Location" value="/resources/sitemap.cfm">
        <cfheader statuscode="307" statustext="Temporary Redirect">
        <cfabort>
</cfif>

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|
Introducing the Fusion Authority Quarterly Update. 80 pages of hard-hitting,
up-to-date ColdFusion information by your peers, delivered to your door four 
times a year.
http://www.fusionauthority.com/quarterly

Archive: 
http://www.houseoffusion.com/groups/CF-Talk/message.cfm/messageid:254698
Subscription: http://www.houseoffusion.com/groups/CF-Talk/subscribe.cfm
Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4

Reply via email to