You can make a 404.php file. That is a normal file to have as part of your theme. You can handle all of your logic in there and have it load your dynamic html in it.
OR
You can use a function like the following in your functions.php file. I just tested and you can get most of what you need from the URL using the var_dump()
placed in this function.
// borrowed from http://wordpress.stackexchange.com/a/1883/10907
function stoi2m1_404_override() {
global $wp_query;
// return if not a 404 page
if (!$wp_query->is_404)
return;
// dump the data in the query, parameters from the URL
echo '<pre>';
var_dump($wp_query->query);
echo '</pre>';
/* resulted in something like this for me, Im using a custom post type movies
array(4) {
["page"]=>
string(0) ""
["movies"]=>
string(4) "missing"
["post_type"]=>
string(6) "movies"
["name"]=>
string(4) "missing"
}*/
if ($wp_query->query['name'] == 'missing' ) { //what ever name/title of post you are looking for
status_header( 200 ); // set the appropriate header
$wp_query->is_404=false; // set is_404 to false
// apply any more logic you need here
// or include custom template file here
// you will want to keep the usual template from loading
}
}
add_filter('template_redirect', 'stoi2m1_404_override' );