Apache VirtualHost, multiple ServerName in one line
Asked Answered
B

2

13

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?

Bronder answered 23/12, 2014 at 10:58 Comment(0)
L
7

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

Lashawnda answered 23/12, 2014 at 11:9 Comment(1)
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.Bronder
C
18

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.

Calc answered 13/12, 2020 at 7:32 Comment(1)
httpd.apache.org/docs/2.0/mod/core.html#serveralias There's no comma between aliasesAngers
L
7

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

Lashawnda answered 23/12, 2014 at 11:9 Comment(1)
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.Bronder

© 2022 - 2024 — McMap. All rights reserved.