I think I hate Apache now, but on with the issue. It might be a configuration error on my end or just my inability to see what's right in front of me, but I'm trying to configure a sub-domain in Apache and no matter what, it always redirects the sub-domain to the web root of the main domain. My configuration is posted below (and yes, the domain name information was purposefully modified):
<VirtualHost *>
DocumentRoot /var/www/root/
ServerName example.com
<Directory /var/www/root/>
allow from all
Options +Indexes
</Directory>
</VirtualHost>
<Directory /usr/share/squirrelmail>
Options Indexes FollowSymLinks
<IfModule mod_php5.c>
php_flag register_globals off
</IfModule>
<IfModule mod_dir.c>
DirectoryIndex index.php
</IfModule>
# access to configtest is limited by default to prevent information leak
<Files configtest.php>
order deny,allow
deny from all
allow from 127.0.0.1
</Files>
</Directory>
# users will prefer a simple URL like http://webmail.example.com
<VirtualHost *>
DocumentRoot /usr/share/squirrelmail/
ServerName squirrelmail.example.com
</VirtualHost>
You need to enable name-based virtual hosts with
NameVirtualHost *
. Also, I don't know if this matters, but why is the squirrelmail document root defined outside of its VirtualHost container?First: you should indent your configs so they are easier to read. Helps you spot some kinds of errors, too.
I don't really think that this is causing the error, but it's worth a try ;) docs say: The DocumentRoot should be specified without a trailing slash.
I cannot see an error in your virtual host config, and you say it redirects to the default domain, so I don't think the error is on apache's side. Maybe the error is from the index.php you specified – have you set some default host or something in the squirrelmail config so that it redirects? Try to replace the index.php by some file that just prints something and check if that works.