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

I have a website for e.g.

And I have another subdomain for e.g.

Both my main and subdomain point to same directory which is public_html.

I want to block access to 

but not

Please note that this test.jpg is same file for both main and subdomain as they both point to same directory. So how do I block it for subdomain but not for main domain using .htaccess? Or is there any other way of doing that?


share|improve this question

1 Answer 1

up vote 1 down vote accepted

If and in one VirtualHost, easy use .htaccess and mod_rewrite:

RewriteEngine On
RewriteCond %{HTTP_HOST}
RewriteRule ^test.jpg - [F]

$ curl
$ curl
<title>403 Forbidden</title>
share|improve this answer
Thanks it worked perfectly!! – Ali Feb 17 '11 at 4:01

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.