Webmasters Stack Exchange is a question and answer site for pro webmasters. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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.

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

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]
share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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