0

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.

1
  • 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, 2010 at 19:04

3 Answers 3

0

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"

0

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

0
<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>

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .