views:

142

answers:

2

Hey,

I am running Apache2 with multiple vhosts in the sites-enabled folder, each looks a bit like this:

<VirtualHost *:80>
    ServerName site1.com
    ServerAlias www.site1.com

    DocumentRoot /home/sites/site1/www/
    <Directory /home/sites/site/www/>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
    </Directory>

    <Directory /home/sites/mainsite/www>
        Options Indexes FollowSymLinks MultiViews
        AllowOverride all
        Order allow,deny
        allow from all
    </Directory>

    # Provide default favicon.ico and robots.txt using rewrite
    RewriteOptions Inherit
    RewriteEngine On
    RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
    RewriteRule ^/(robots\.txt|favicon\.ico)$ /mainsite_alias$0 [PT,NC,L]
</VirtualHost>

The Rewrite code is common to all vhosts (providing a default favicon.ico/robots.txt) but putting this code into httpd.conf does not seem to have any effect - the rewrite logs show nothing.

How can I make this code common to all vhosts without duplicating the code?

Alternatively - is there a better way of achieving default favicons?

Thanks

A: 

You could try a AliasMatch:

AliasMatch ^/(robots\.txt|favicon.ico)$ /home/sites/site1/www/mainsite_alias$0
Gumbo
A: 

I am using this

<VirtualHost *:80>
    ServerAdmin email_at_isp
    DocumentRoot "C:/apache/htdocs"  
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin admin_at_server_one.com
    DocumentRoot "C:/apache/htdocs/server_one.com"
    ServerName server_one.com
    ErrorLog "logs/server_one.com-error.log"
    CustomLog "logs/server_one.com-access.log" common
</VirtualHost>

and I keep rewrite scripts in .htaccess at the root[C:/apache/htdocs] I hope it helps somehow, if not enoying. lol

P.M