Handling multiple vhosts can be tricky,
Especially if more than one, but not all, vhosts share a large amount of
common configuration. For example you often want Aliases and Users shared
between http (non-ssl) and https (ssl) vhosts for the same server.
-------------------------------------------------------------------------------
VHost order is important.
VHosts are matched in the order given. But the first VHost defined handles
anything that is not mentioned by any other VHost and should be provided.
As such to create your 'default' Primary VHost first...
ServerName primary-server.domain
...
ServerName primary-server.domain
...
I also recommend instead that you add a final 'match all' vhost LAST...
ServerName primary-server.domain
ServerAlias *
Redirect permanent / http://primary-server.domain
ServerName primary-server.domain
ServerAlias *
Redirect permanent / http://primary-server.domain
This is not technically needed but it ensures unmatched vhosts are redirected
to the real primary vhost entry.
NOTE: That if you want to redirect SSL vhosts, you do need a SSL certificate to
avoid SSL errors. However you cannot get a SSL cert for a match all VHOST.
-------------------------------------------------------------------------------
HTTPS Handling
See also "info/www/apache_rewrite.txt" document
For http(s) shared webservers a simple method would be to use a mod re-write
to redirect all http requests to the https vhost, then serve all the special
configuration from there.
For example
ServerName ....
# Force use of HTTPS
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
ServerName ...
# all the configuration needed for that server
OR without using Mod-rewrite...
WARNING: This will lose the URI path of the users request!
But is suitable for a new web server without existing links.
ServerName ....
redirect permanent / https://primary-server/
------------------------------------------------------------------------------
VHost Redirection
A Proxy server is just a web server. As such you can also use it to test
what it will do with a VHost request. But only for non-HTTPS protocol!
For example
If an apache webserver has...
ServerName www.old-domain
ServerAlias hostname.old-domain
ServerAlias hostname.new-domain
Redirect permanent / http://www.new-domain/
With DNS CNAME aliases pointing to the new host
Test with
curl --head --proxy www.old-domain:80 www.old-domain
That will return...
HTTP/1.1 301 Moved Permanently
...
Location: http://www.new-domain/
...
SSL VHosts (port 443), still require a SSL certificate to avoid SSL errors
during the redirection. However you can include all the old hosts into the
new hosts certificate and use it for the redirecting VHost.
-------------------------------------------------------------------------------