i use phpbb and use a custom page for the error page. as descalzo said you need to place those codes in ur .htaccess file and then make sure to have a 404 page or error page.
common error page is .shtml but it can be anything really. php and shtml are the best choices. but really shtml gives more options as it can give referrer, ip, file missing request.
php can do that as well but more complicated