Apache::RefererBlock will examine each request. If the MIME type of the requested file is one of those listed in RefBlockMimeTypes, it will check the request's Referer header. If the referrer starts with one of the strings listed in RefBlockAllowed, access is granted. Otherwise, if there's a RefBlockRedirect directive for the referrer, a redirect is issued. If not, a "Forbidden" (403) error is returned.
Available from CPAN. See the module manpage for more information.