Server Fault is a question and answer site for system and network administrators. 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 have a fairly default Apache install on Ubuntu 10.10. There's no virtual hosting and I would rather not add that. All domains that map to that machine are therefore served by the default site and the same directory.

What I would like is the .htaccess file in a specific directory to disallow access from a specific domain to that directory.

To clarify, gives a 403 (or whatever), but any other sub-domain or domain permits access to the file.

share|improve this question
up vote 2 down vote accepted

You could try something like (untested and Rewrites never seem to work right the first time for me):

RewriteCond  %{HTTP_HOST}  ^
RewriteRule  ^/thefile.html$  [FL]

This should cause the one file to be returned as "forbidden" on the matching domain. The RewriteLog filename.log is helpful in debugging rewrites. See the official documentation for more on Rewriting.

share|improve this answer

You can't do that without vHosting. If you can wait till 4pm eastern, I'll give you the code to do so. I'm not around my server now.

share|improve this answer
Thanks for your answer, I know how to do virtual hosting if it's needed, it just affects my backup and costs me time. Surely, it's possible as a rewrite rule though? – David Sep 7 '11 at 10:53
This is definitely doable with mod_rewrite without using virtual hosting. – jgoldschrafe Sep 7 '11 at 12:59

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.