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

The problems I'm facing is how to prevent hotlinking from within a website. What I want to do is to block from hotlinking a CSS, but allow to use the CSS using .htaccess.

-Both user xxx and user aaa is using css file, I only want to allow user aaa to be able to use it and not user xxx

What I manage to come up with so far is is putting a .htaccess in to only allow user aaa to hotlink the css.

RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http(s)?://( [NC]
RewriteRule \.(css|jpg|jpeg|png|gif)$ [NC,R]

When I put this into the .htaccess it blocks both and from hotlinking the css

What I want to do is allow only this page to use the css and block anything else from hotlinking it.

share|improve this question
You have opening bracket in your 2nd RewriteCond but no closing one -- is that a typo or what? Does it work if it will be removed? – LazyOne Jul 4 '11 at 23:49
Wow I can't believe I overlooked that, yes you're right I didn't close it. I just closed it and it seems that it now allows the .css to be hotlink on both (user xxx and user aaa) sadly. – John Smith Jul 4 '11 at 23:56
You better turn rewrite debug ON and check what data is passed in %{HTTP_REFERER} -- maybe it is completely different URL. – LazyOne Jul 4 '11 at 23:59
Woops I misread your post. Yes I ended up having a pointless ( in there. I just removed it and every works fine now. Thanks for your advice haha. – John Smith Jul 5 '11 at 0:03

According to the above comments there were mismatched parenthesis in the rule. Fixing syntax apparently worked and now the rewrite rule works as expected.

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.