.htaccess - Allow Only By Referer


Good afternoon-

I have browsed the forums as well as the web looking for an answer to this question. Hope someone out there can help.

I need to create a .htaccess file that will only allow the files in the folder to be seen if the "referer" is from a particular site (or possibly two sites). I have found a lot of solutions out there for people who want to block specific sites, but I can't seem to figure out how to only allow specific sites. I have done some trial and error based on some of the things I have found, but with no luck.

Any ideas?

Thanks in advance!




Hi David,

Welcome to the forums

I haven't tested it, but try;

RewriteEngine on
RewriteBase /
RewriteCond %{HTTP_REFERER} !^http://www\\.your\_domain\_name\\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www\\.OKdomain1\\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^http://www\\.OKdomain2\\.com/ [NC]
RewriteRule ^.*$ http://www.your\_domain\_name.com/not\_allowed\_here.htm [R=301,L]

or I'd try something along those lines anyway - with the not_allowed_here.htm being a page I redirected all those I don't want to.