Apache VirtualHost, multiple ServerName in one line

48.9k views Asked by At

I am using the following tag

<VirtualHost *:80 *:443>

    ServerName blog.mydomain.com
    ServerAlias blog

to create a virtual host. I've put the ServerName as my subdomain which is blog. However, i'm trying to figure out a way to add www.blog. aswell in the same line rather than having to create a completely new virtual host.

Is there a way for this to be done?

2

There are 2 answers

1
Hans Z. On BEST ANSWER

sure, you can add multiple entries to the ServerAlias, see: http://httpd.apache.org/docs/2.2/mod/core.html#serveralias

1
Abdulbasit On

Apache allows multiple server Aliases

<VirtualHost *:80>
     
     ...

     ServerName blog.mydomain.com
     ServerAlias www.blog.com
     ServerAlias blog
     ServerAlias add-as-many-as-you-want

     ...
    
</VirtualHost>

The Above can also be achieved as

<VirtualHost *:80>
     
     ...

     ServerName blog.mydomain.com
     ServerAlias www.blog.com blog add-as-many-as-you-want

     ...
    
</VirtualHost>

So you can choose what you want from the two.