Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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'm trying to block access to my website depending on whether a visitor had visited the site through another website. The latter has been using up my traffic by using an iframe to display content through his site, masking my site's identity.

I have mod_env_if activated in apache2.

ErrorDocument 403 /error403.html
SetEnv noaccess=0
SetEnvIf Referer "^http://sitetoblock\.tk/" noaccess=1
SetEnvIf Referer "^http://www\.sitetoblock\.tk/" noaccess=1

<FilesMatch "\.(gif|png|jpe?g|php|html)$">
Order Allow,Deny
Deny from env=noaccess


The problem is that this directive is blocking all traffic including direct visitors to the site. What am I doing wrong?

share|improve this question
In the documentation they sometimes omit the quotes in their examples. Maybe give it a try? Also, why the last forward-slash after "tk"? – Uwe Keim Aug 26 '13 at 4:22
up vote 1 down vote accepted

In your configuration, default access state is "Deny" because you have "Order Allow,Deny". Change the Order to "Deny, Allow" so you can explicitly deny access based on your referer check.

share|improve this answer
Thanks, that worked! – Droidzone Aug 26 '13 at 4:45

You need to escape out the dots in the urls, like:

SetEnvIf Referer "^http://sitetoblock\.tk/" noaccess=1
SetEnvIf Referer "^http://www\.sitetoblock\.tk/" noaccess=1
share|improve this answer
I escaped the periods, but it still denies access to everyone. Qn edited. – Droidzone Aug 26 '13 at 4:13

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.