11

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?

lfurini
  • 3,729
  • 4
  • 30
  • 48
John
  • 6,417
  • 9
  • 27
  • 32

2 Answers2

12

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.

Abdulbasit
  • 534
  • 8
  • 13
  • https://httpd.apache.org/docs/2.0/mod/core.html#serveralias There's no comma between aliases – cl0ne Mar 27 '23 at 15:14
6

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

Hans Z.
  • 50,496
  • 12
  • 102
  • 115
  • I tried that before posting, but it didnt work. But I tried: ServerAlias blog www.blog, also tried: ServerAlias blog www that also did not work, then tried ServerAlias blog www.blog.mydomain.com and this worked. – John Dec 23 '14 at 12:13