Apache2 - Virtual Host redirect problem with multiple domains

Discussion in 'Apache' started by kevtucker, May 25, 2012.

  1. #1
    Hi, looking for a bit of help with Apache2 on Ubuntu Desktop.

    I have 2 domain names : example1.com and example2.com but having problems with redirecting.

    If I type www.example1.com I get my homepage for Example 1
    If I type example1.com I get Example 1 homepage again
    If I type www.example2.com I get my homepage for Example 2

    now the problem here is If I type example2.com it takes me to Example 1 homepage.

    I have this in /etc/apache2/sites-available/default

    <VirtualHost *:80>


    ServerAdmin webmaster@example1.com


    DocumentRoot /var/www/
    <Directory />
    Options FollowSymLinks
    AllowOverride All
    </Directory>


    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    </Directory>


    ErrorLog ${APACHE_LOG_DIR}/error.log


    # Possible values include: debug, info, notice, warn, error, crit,
    # alert, emerg.
    LogLevel warn


    CustomLog ${APACHE_LOG_DIR}/access.log combined


    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
    ServerName example1.com
    ServerAlias *.example1.com
    </VirtualHost>



    and then in /etc/apache2/sites-available/example2.com.conf I have

    <VirtualHost *:80>
    DocumentRoot /Websites/example2
    ServerName example2.com
    ServerAdmin webmaster@example2.com
    <Directory />
    Options FollowSymLinks
    AllowOverride None
    </Directory>
    ScriptAlias /cgi-bin/ /usr/lib/cgi-bin/
    <Directory "/usr/lib/cgi-bin">
    AllowOverride None
    Options +ExecCGI -MultiViews +SymLinksIfOwnerMatch
    Order allow,deny
    Allow from all
    </Directory>
    ErrorLog /var/log/apache2/error.log
    LogLevel warn
    CustomLog /var/log/apache2/access.log combined
    Alias /doc/ "/usr/share/doc/"
    <Directory "/usr/share/doc/">
    Options Indexes MultiViews FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
    Allow from 127.0.0.0/255.0.0.0 ::1/128
    </Directory>
    <Directory /Websites/example2>
    allow from all
    Options +Indexes
    </Directory>
    ServerAlias *.example2.com
    </VirtualHost>

    I set the hosts up using Webmin so I think that is why I have two seperate .conf files in /sites-available/

    Does any one have a solution for me on this. I've tried many things but still not working correctly.

    Thank you for any help.

    Kevin
     
    kevtucker, May 25, 2012 IP