I have very specific problem and I don't even know if I am asking at right place and if it is even possible.

I have two domains, lets say domain1.com and domain2.com. Both domains share same root directory. So each file from www.domain1.com/file_url is accessible also as www.domain2.com/file_url

I am looking for a way, how to disable SOME of the files when requested with domain2.com. But not all of them, but just selected ones. Is it possible to set some "flag" or attribute for a file so Apache would recognize it and denied it when requested with domain2.com ?

Right now, the only solution which come to my mind is to create PHP script and use rewrite of each file in the directory and implement this "flag" checking inside this PHP file. But that would cost a lot of system resources, so I would thought if this could be done else ?


I have forgotten to specify that I am dealing with MANY files ( = thousands ), so I am not able to manually change config file for Apache. And those files are constantly growing since they are user-uploaded. Sorry I forgot to mention this important detail.

2 Answers 2

RewriteEngine on

RewriteCond %{HTTP_HOST} ^www.domain1.com$
RewriteRule ^filefordomain2.png$ - [F,L]

RewriteCond %{HTTP_HOST} ^www.domain2.com$
RewriteRule ^filefordomain1.png$ - [F,L]

In your RewriteRule you can also work with Regular expressions for multiple files.


If you have control over the server (or at least the virtualhosts), you can deny access for specific files or folders in the virtualhost directive. If not, you can work with .htaccess.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.