Q:

Deny direct access to folder except from specific URL

I was wondering if anyone knows if this is possible. Im trying to limit access to www.mydomain/PROJECT1 while making the same folder accessible through a colour box from www.mydomain/portfolio.php but im not having much luck. 
Any help would be greatly appreciated

A:

Edited to include both 404 error and 301 redirect.
I'm not sure if this is what you are going for, but I have limited direct access to certain folders in my site realm, but my scripts and files are able to access them. 
In my htaccess file in the folder I wish to block I have the following:
RewriteEngine ON

RewriteCond %{HTTP_REFERER} !^http://domain.com [NC]
RewriteRule ^.*$ - [R=404,L]

Replace domain.com with valid regex of allowed site address
This makes the browser display a 404 error (custom errors handled in a top level .htaccess). I chose this rather than a redirect, because unless checking server headers and such (hackers not site users) they wouldn't know the file is there. If you redirect back to a different page, especially on slower internet connections, the redirect is obvious.
RewriteEngine ON

RewriteCond %{HTTP_REFERER} !^http://allowedURL\.com [NC]
RewriteRule ^.*$ http://mysite.com [R=301,L]

This will redirect from whatever they tried to access from that folder, to mysite.com

