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.

  • 1
    I hope you are not using it to keep a user logged in instead of using sessions or protected directories. Jan 7, 2012 at 17:11

1 Answer 1


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]

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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