Take the 2-minute tour ×
Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

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, xxx.foo.com/thefile.html gives a 403 (or whatever), but any other sub-domain or domain permits access to the file.

share|improve this question

2 Answers 2

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}  ^xxx.foo.com
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
1  
This is definitely doable with mod_rewrite without using virtual hosting. –  jgoldschrafe Sep 7 '11 at 12:59

Your Answer

 
discard

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.