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

We've got multiple sites that are pointing to the same directory. This is because they are basically the same site, the only differce is, the language. Now we've got a plan to change the design for only one of these sites. We want to keep the complete structure of the site, so moving is no option. But we want only a couple of files different from the other sites. I want to create the following situation in apache:

Two directories:

  • /website/dir_A
  • /website/dir_B

When let's say an image is called: http://website/img/logo.png It has to give logo.png back that is part of dir_A. If dir_A doesn't contain logo.png, it has to give logo.png back that is part of dir_B.

I had hoped "Alias" could do this, but couldn't.

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

You can do this with mod_rewrite. I think doing something like this should work:

DocumentRoot /website/dir_A
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ /website/dir_B/$1 [L]
share|improve this answer
    
You might consider putting all of the rewrite-related directives in a <Location> block so as to specify that the rewrites would only apply to the directory that could contain files he wants to serve. –  Clint Miller Jul 8 '10 at 14:40
    
how do you mean with location? And the rule should point to the directory within the documentRoot set within Virtualhost? <VirtualHost :80> ServerName example.com DocumentRoot /home/abc/example.com/htdocs <location /img> RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f RewriteRule ^(.)$ /site/bbb/img/$1 [L] </location> </VirtualHost> –  Ronald Oldenburger Jul 8 '10 at 15:06
add comment

I don't know of a way to do this via Apache directly, but if you are running on a dedicated server of VPS (rather than shared hosting) running Linux you could use a union filesystem to achieve this.

share|improve this answer
add comment

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.