0

I have a server with multiple websites in subfolders that I want to give their own domains. I'm got two subdomains setup using VirtualHost as such:

<VirtualHost *:80>
    DocumentRoot "/var/www/ex1"
    ServerName ex1.domain.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/ex2"
    ServerName ex2.domain.com
</VirtualHost>

They are setup as A records in my DNS, and they work fine when accessing ex1.domain.com and ex2.domain.com, and the main domain www.domain.com works as well.

However, when I setup their main domains, www.example1.com as CNAME record redirecting to ex1.domain.com, visting www.example1.com shows me www.domain.com and not ex1.domain.com as it should.

What am I doing wrong?

0

ServerAlias directive should do the trick:

<VirtualHost *:80>
    DocumentRoot "/var/www/ex1"
    ServerName ex1.domain.com
    ServerAlias www.example1.com
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "/var/www/ex2"
    ServerName ex2.domain.com
    ServerAlias www.example2.com
</VirtualHost>
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.