Server Fault is a question and answer site for system and network administrators. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I have various virtual hosts (vhosts) setup on an Apache 2.2 server such as:


On virtual hosts matching the regular expression "site[a-z].domain", I want to be able to serve the same file (say logo.gif) from /usr/local/apache/files/logo.gif .

If I wanted to do it on each site, I would obviously have to have something like:

<VirtualHost *:80>
ServerName testsitea.domain
Alias /logo.gif /usr/local/apache/files/logo.gif

<VirtualHost *:80>
ServerName testsiteb.domain
Alias /logo.gif /usr/local/apache/files/logo.gif

etc etc

But, for various reasons, I cannot ensure the VirtualHost will be setup with the alias in place and therefore I need to make it a global Apache setting, but with regular expression matching on the ServerName.

Can anyone point me in the correct direction if this is at all possible?

share|improve this question

I have a suggestion, I don't know if it's ok for your environment but it can give you idea. I don't know how to do that with Alias but maybe you can use mod_rewrite, to do the same things. First of all create a site like common.domain this virtual host will be use to store all files use by others sites.

Create a Global rewrite rule to perform redirection ,thread on stackoverflow . You can define this rewrite rule in a Directory section , example if all your vhosts are store under directory /var/www/vhosts like this: * /var/www/vhosts/siteA.domain/

  • /var/www/vhosts/siteB.domain/

  • /var/www/vhosts/siteC.domain/

  • /var/www/vhosts/siteD.domain/

You can define the the rewriterule like that :

<Directory /var/www/vhosts>
                Options FollowSymLinks
                AllowOverride None
                RewriteEngine On
                RewriteCond "%{HTTP_HOST}" "site[a-z]*\.example\.com" [NC,OR]
                RewriteCond "%{SERVER_NAME}" "site[a-z]*\.example\.com" [NC]
                RewriteRule "/logo.gif"  "" [L]

# example:
# RewriteRule "/logo.gif" "" [L]


So you have Virtual Host matching , and you can do wathever you want , and you can apply this solution for many web server.

I think it's the best solution or you can define the global rewrite rule in the httpd.conf outside the parent directory . The problem with this solution you will need to add this in each virtualhost :

RewriteOptions inherit

Because by default rewrite rule are not apply in VirtualHost. You have more information on the stakoverflow thread

Have a nice day.

share|improve this answer

Your Answer


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.