Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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 ?

EDIT:

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.

share|improve this question

migrated from stackoverflow.com May 10 '11 at 11:30

This question came from our site for professional and enthusiast programmers.

2 Answers 2

up vote 1 down vote accepted
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.

share|improve this answer

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.

share|improve this answer

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.