Restrict access to webpage from single referrer domain using .htaccess
<p>I want to restrict access to a website to only allow referrers from a single domain. I can't get the .htaccess file to work correctly.
Say I am referring from <a href="http://domainname.com" rel="nofollow">http://domainname.com</a> - access will be allowed.
Or <a href="http://subdomain.domainname.com" rel="nofollow">http://subdomain.domainname.com</a> - access will be allowed.</p>

<p>But any other referrer (or typing in URL) will block, and direct to Access Denied page. </p>

<p>Code as follows (note I need to allow access from ANY referrer page on domainname.com</p>

<pre><code>RewriteEngine On
RewriteBase /

# allow these referers to passthrough
RewriteCond %{HTTP_REFERER} ^http://(protect|unprotected)\.domainname\.com
RewriteRule ^ - [L]

# everybody else receives a forbidden
RewriteRule ^ - [F]

ErrorDocument 403 /forbidden.html
</code></pre>