Not sure on Apache, but on IIS you can set up a custom error
page for a 404 error. This custom error page can be any file
(including .cfm) that is accessible from the root of the site. So,
if you go into iis and set a custom error for 404, you can point it
to something like /404Handler.cfm, then create the 404Handler.cfm
template in the root of your website. Inside this file you can do
what ever you like, including redirecting to the home page. One of
the nice features of how iis handles 404 errors is that the URL of
the page that was requested will be stored in the CGI.query_string.
For example, if a user types in
http://www.yoursite.com/foobar.html
and /foobar.html does not exist, the user will be forwarded to
/404Handler.cfm and CGI.query_string will be 404;/foobar.html.
This is a very easy way to handle friendly URLs as well. for
example let's say you have a user table that has a username and
useid field. Now let's also say you have a profile.cfm themplate
that takes in the URL variable called userid, and then looks up the
user and displays the user's profile. Using the method above, you
can create a friendly URL like
http://www.yoursite.com/users/username,
however you do not create a users directory. If a user types in
this URL he/she would normally get a 404 error, but since you
redirected to the 404Handler.cfm, you can get the URL by saying
<cfset target=ListLast(cgi.query_string,";")>, then check to
see if target url contains /users (<cfif target contains
"/users">). If it does, you can get the username by saying
<cfset username=ListLast(target,"/")>. Once you have the
username you can then query the database to figure out what the
userid is and then redirect to profile.cfm. It seems a little
convoluted, but it works.