I know the HTTP_REFERER method has a security loop, but it most cases it works fine. How can i use it, to limit how a user see other pages on my website, instead of just directly clicking on the link or pasting it on the browser. Specifically, i want the referer to only work if the referred url came from the same domain name? And not from another source.

link|improve this question
1  
I hope you are not using it to keep a user logged in instead of using sessions or protected directories. – Marco Demaio Jan 7 at 17:11
feedback

1 Answer

With Apache, to protect a directory (e.g. your /images directory) something like this in a .htaccess file works:

RewriteEngine On

RewriteCond %{HTTP_HOST};%{HTTP_REFERER} !^([^;]+);http://\1(/.*)?$
RewriteRule .* /please_dont_hotlink.html [R]
link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.