ErrorDocument 404 /generate-page.php
<?php
if (preg_match('^/article-(\d+).html$!', $_SERVER['REDIRECT_URI'], $m)) {
ob_start();
/* Do stuff to generate page */
$data = ob_get_contents();
ob_end_clean();
echo $data;
$fn = "article-$m[0].html.".getmypid();
$fd = fopen($fn, "w") or exit;
fputs($fd, $data);
fclose($fd);
rename($fn, "article-$m[0].html");
} else {
header("HTTP/1.0 404 Not found");
/* Generate 404 message here */
}
?>