I use .htaccess to rewrite urls from site.com/persons/firstname-lastname/ to persons.php?person=firstname-lastname
If you type the url-friendly name of a person that exists in the database, then everything works fine. The problem with the way I've done it is that you can type anything in the address bar as long as it matches the rewrite rule even if there's no such record in the database. So if you go to /persons/rubbish/, you just get a blank page. I checked the response headers, and it says 200 OK. What should I do in order to get a 404 Not Found in such cases?

This is what my .htaccess looks like:
Code:
RewriteEngine on

RewriteRule ^(people)$ /$1/ [R]
RewriteRule ^(people)/$ $1.php

RewriteRule ^(people)/([a-z0-9-]+)$ /$1/$2/ [R]
RewriteRule ^(people)/([a-z0-9-]+)/$ $1.php?person=$2
And this is the relevant PHP code:
PHP Code:
<?php
include "../../includes/dbconn.php";

if(isset(
$_GET['person'])) {

    
$person_url $_GET['person'];
    
    function 
quote_smart($person_url)
    {
       
// Stripslashes
       
if (get_magic_quotes_gpc()) {
           
$person_url stripslashes($person_url);
       }
       
// Quote if not a number or a numeric string
       
if (!is_numeric($person_url)) {
           
$person_url "'" mysql_real_escape_string($person_url) . "'";
       }
       return 
$person_url;
    }
    
    
$sql sprintf("SELECT * FROM persons WHERE person_url='$person_url'",
            
quote_smart($person_url));
    
$result mysql_query($sql) or die("Unable to perform query. Reason: ".mysql_error());
    
$row mysql_fetch_array($resultMYSQL_ASSOC);

    
$first_name stripslashes($row['first_name']);
    
$last_name stripslashes($row['last_name']);
    
    
// and here's where the contents of the page will be.

} else {
    
// display list of all people.
}
?>