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:
DocumentRoot "/var/www/ex1"
ServerName ex1.domain.com
DocumentRoot "/var/www/ex2"
ServerName ex2.domain.com
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?
Answer
ServerAlias directive should do the trick:
DocumentRoot "/var/www/ex1"
ServerName ex1.domain.com
ServerAlias www.example1.com
DocumentRoot "/var/www/ex2"
ServerName ex2.domain.com
ServerAlias www.example2.com
No comments:
Post a Comment