We recently needed to move several hundred mail domains from standard http to SSL secured HTTP (HTTPS). To do so, we chose one domain and used mod_rewrite to redirect to that domain. To make things more complicated, we also wanted to strip off the first part of the domain name.
If you were doing this for just one domain (or a small number) then you should be using a simple Redirect in a VirtualHost to accomplish this. However, since we needed to do it for a large number of domains, mod_rewrite was necessary to capture the hostname in a dynamic fashion.
As an example, our users were visiting:
to access their webmail and
to access their mail administration interface.
Our software only requires the
section of the hostname, and so we needed to redirect to
Our rewrite rules look something like this:
On the SSL virtual host, we then pick up the hostname with the following rewrites:
Hope someone finds this useful, it took me a few hours to find the correct documentation to obtain the HTTP_HOST to use in the RewriteRule.