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.

I'm trying to achieve the following result:

I have multiple domains pointing to the same documentroot, which contain files that are being used on all domains (index.php, css files, and such):

C:/cms/

Then I have several domains:

  • www.domain1.com/*
  • fr.domain1.com/*

Should both point to D:/files/domain1.com/*

  • www.domain2.com/*
  • de.domain2.com/*

Should both point to D:/files/domain2.com/*

However

  • www.domain1.com/adminstyle.css
  • fr.domain1.com/adminstyle.css
  • www.domain2.com/adminstyle.css
  • de.domain2.com/adminstyle.css

Should all point to C:/cms/adminstyle.css (If A file is not found in the "per domain" directory, it should fall back to the "general" directory)

Is this possible with apache? I've been messing around with virtual hosts/directories and aliases but without succes yet.

share|improve this question
    
I've solved it by routing everything to index.php and then use readfile to read the appropriate file in the right directory. However There must be more performant and elegant solutions around? –  brechtvhb Oct 3 '10 at 19:04
add comment

3 Answers

You could do something like:

NameVirtualHost 1.2.3.4:80
Alias /shared D:/files/shared

<VirtualHost 1.2.3.4:80>
ServerName domain1.com
ServerAlias www.domain1.com *.domain1.com
DocumentRoot D:/files/domain1.com
</VirtualHost>

<VirtualHost 1.2.3.4:80>
ServerName domain2.com
ServerAlias www.domain2.com *.domain2.com
DocumentRoot D:/files/domain2.com
</VirtualHost>

Put your common files in D:/files/shared and refer to them as img src="/shared/whatever"

share|improve this answer
add comment

This should do it.

RewriteEngine on
RewriteCond %{REQUEST_URI} ^/adminstyle\.css$
RewriteCond %{DOCUMENT_ROOT}/adminstyle.css !-f
RewriteRule ^(.+) C:/cms/adminstyle.css [L]
RewriteRule ^(.+) - [PT]

See: http://httpd.apache.org/docs/2.2/rewrite/rewrite_guide.html#multipledirs

share|improve this answer
add comment
<VirtualHost *:80>
    DocumentRoot c:/cms/
    ServerName shared.domain1.com
    ServerAlias shared.domain2.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot c:/files/domain1.com/
    #Yes, taking liberty with the name of your domain(s) here.  Correct it if my assumptions are wrong.
    ServerName domain1.com
    ServerAlias *.domain1.com

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) http://shared.domain1.com/$1 [L,QSA]
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot c:/files/domain2.com/
    #Yes, taking liberty with the name of your domain(s) here.  Correct it if my assumptions are wrong.
    ServerName domain2.com
    ServerAlias *.domain2.com

    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule (.*) http://shared.domain2.com/$1 [L,QSA]
</VirtualHost>
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.