Subdomain always redirects to main domain. Why

apache-2.2subdomainvirtualhost

when I request site1.example.com I get redirected to example.com. In /etc/apache2/sites-available/ I have setup a site1.example.de file with following content

<VirtualHost *:80>
    ServerName site1.example.com
    DocumentRoot "/var/www/vhosts/example/site1"
        <Directory /var/www/vhosts/example/site1>
          Allow from all
          AllowOverride All
        </Directory>
</VirtualHost>

After

sudo a2ensite site1.example.com

and reloading apache it still redirects me to main domain. Any ideas why?

I use apache2/2.2.14 (Ubuntu 10.4). My server is acting as nameserver.

Best Answer

Those wacky configs from /var/www/vhosts/ (looks like they're from Plesk?) are using the full IP as their vhost address declaration, so the *:80 listener won't ever get any requests to that IP. Assuming that you only have that one IP on your server, this isn't desired.

Change the <VirtualHost> line in your newly created host, to have it be used for requests that hit the Plesk-created name-based vhost:

<VirtualHost 83.169.46.168:80>
    ServerName site1.example.com
    DocumentRoot "/var/www/vhosts/example/site1"
    <Directory /var/www/vhosts/example/site1>
        Allow from all
        AllowOverride All
    </Directory>
</VirtualHost>
Related Topic