[H-GEN] Multiple Domains - Apache
Matthew Brecknell
humbug at brecknell.org
Mon Apr 28 20:02:25 EDT 2008
Deepan said:
> I am serving two domains from the same machine
> using Apache. I want www to be used in both of the
> domains, hence I redirect urls without www to
> appropriate urls with www.
>
> [config snipped]
Not sure, but I think your problem may be due to virtual host
"defaulting" for server names which apache does not know about. I
usually add a "dummy" server before any of my actual virtual hosts to
help me discover bad virtual host configs.
Anyway, here's how I do the www redirection:
<VirtualHost *>
ServerName a.example.com
Redirect permanent / http://www.a.example.com/
</VirtualHost>
<VirtualHost *>
ServerName www.a.example.com
DocumentRoot /var/www/vhost/a.example.com
</VirtualHost>
<VirtualHost *>
ServerName b.example.com
Redirect permanent / http://www.b.example.com/
</VirtualHost>
<VirtualHost *>
ServerName www.b.example.com
DocumentRoot /var/www/vhost/b.example.com
</VirtualHost>
This has the added advantage that the redirect is performed in the
browser, not the server. This increases the value of any caching which
is performed outside the server.
More information about the General
mailing list