Below is the code you need.
...................................................
RewriteEngine on
RewriteCond %{HTTP_REFERER} !.../calproj/.
RewriteCond %{HTTP_REFERER} !.../access/.
RewriteCond %{HTTP_REFERER} !.../calendar/.
RewriteRule .* ../calendar/denyaccess.php
..................................................
Lines 2, 3, 4 are all the same thing. Put in there the directories which contain files which you WANT to be allowed access. Include the directory in which the .htaccess file is situated.
The RewriteRule is simply a notice to all the naughty people who try to access files directly.
You should place one page outside the programs directory with no protection - simply a html file to input the username and password.
One problem you will get is from people who have got their browsers caching. This includes those who have got MSIE 6 set to auto. They must set their browsers to access the Net directly.
'Doctored' browsers such as those from AOL can also be troublesome. Get AOL users to install a virgin browser if possible - firefox is a better browser anyway - you can add lots of bells and whisles (extensions)