0

www.example.com. 1800 IN CNAME example.com.

other.example.com. 1800 IN CNAME example.com.

Which method is correct in Apache when all entries point to the exact same DocumentRoot?

Would the following method work?

<VirtualHost *:80>
        DocumentRoot "/some/place/"
        ServerName example.com
</VirtualHost>

OR I shall create an VirtualHost entry for each CNAME?

<VirtualHost *:80>
        DocumentRoot "/some/place/"
        ServerName example.com
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot "/some/place/"
        ServerName www.example.com
</VirtualHost>

<VirtualHost *:80>
        DocumentRoot "/some/place/"
        ServerName other.example.com
</VirtualHost>
3

Your first method would not work reliable (only if it is the default VirtualHost).
Your second method will work but duplicates configuration - something you generally want to avoid.

You could use ServerAlias (http://httpd.apache.org/docs/2.2/mod/core.html#serveralias) instead:

<VirtualHost *:80>
        DocumentRoot "/some/place/"
        ServerName example.com
        ServerAlias www.example.com other.example.com
</VirtualHost>

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.