Apache Virtual Host Not Matching ServerAlias

apache-2.2httpsvirtualhost

I have a VirtualHost block defined like this for a domain:

<VirtualHost *:443>
    ServerName example.com:443
    ServerAlias www.example.com:443

If I use this URL, https://example.com/, the site loads as expected. When I use this URL, https://www.example.com/, Apache is delivering the content and SSL certificate for the very first virtual host defined in my config.

I understand the definition order of virtual hosts is significant, so it seems to me that the ServerAlias directive is not being matched for some reason. My web searches haven't turned up a clue for how to fix this issue.

Best Answer

Because you didn't care to read documentation on the ServerAlias Directive and therefore you have a wrong syntax.

ServerAlias hostname [hostname] ...

That's different from ServerName that can have optional port and scheme, but only one hostname:

ServerName [scheme://]fully-qualified-domain-name[:port]
Related Topic