You need an intelligent 404 handler. If Apache throws a 404 (File not found) error the intelligent handler should try to salvage the event by looking at the pattern of the URL, and locating a known resource to serve instead. You should also handle the possibility that the fall back image might also not be there.
This page can show you how to check if a file is present, but the logic will need to be in the last line.
http://www.phpriot.com/articles/search-engine-urls/5
RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1
Or you can go the .htaccess route (I think that's cleaner)
http://httpd.apache.org/docs/2.2/mod/core.html#errordocument
Assuming you could use .htaccess and PHP here is one solution:
Add this line to your .htaccess:
ErrorDocument 404 /error.php
Then add this code to you error.php like this
<?php
if(preg_match("/^/images/thumbnail/", $_SERVER['REQUEST_URI'])) {
//do a 302 redirect
header( 'Location: /images/defualtImage.jpg' ) ;
} else {
//You need to go somewhere to handle actual 404 errors
header( 'Location: /static/404.html' ) ;
}
?>
302 redirect directs would work best here.