I have many VirtualHost
and it seems that we need to do these two lines each time:
<VirtualHost *:80>
...
ServerName www.example.com
ServerAlias example.com
Is there a one-line solution that allows to do this?
<VirtualHost *:80>
ServerName *.example.com # works for both http://example.com and http://www.example.com
i.e. without having to duplicate example.com
?
No, it is not possible.
ServerName
is used to uniquely identify protocol, name and port of a host. It accepts only one parameter and no wildcard.
You can use wildcards in ServerAlias
, and also specify multiple names on it:
ServerAlias *.example.com
or
ServerAlias www1.example.com www2.example.com www3 foo
Source: https://httpd.apache.org/docs/2.4/mod/core.html#serveralias
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With