Apache mod_rewrite for multiple domains to SSL

Posted by Aaron Vegh on Pro Webmasters See other posts from Pro Webmasters or by Aaron Vegh
Published on 2011-02-18T15:46:57Z Indexed on 2011/02/21 23:34 UTC
Read the original article Hit count: 525

Filed under:
|

Hi there, I'm running a web service that will allow people to create their own "instances" of my application, running under their own domain. These people will create an A record to forward a subdomain of their main domain to my server.

The problem is that my server runs everything under SSL. So in my configuration for port 80, I have the following:

<VirtualHost *:80>
    ServerName mydomain.com
    ServerAlias www.mydomain.com
    RewriteEngine On
    RewriteCond %{HTTPS} !=on
    RewriteRule /(.*) https://mydomain.com/$1 [R=301]
</VirtualHost>

This has worked well to forward all requests from the http: to https: domain. But as I said, I now need to let any domain automatically forward to the secure version of itself.

Is there a rewrite rule that will let me take the incoming domain and rewrite it to the https version of same? So that the following matches would occur:

http://some.otherdomain.com -> https://some.otherdomain.com
http://evenanotherdomain.com -> https://evenanotherdomain.com

Thanks for your help! Apache mod_rewrite makes my brain hurt.

Aaron.

© Pro Webmasters or respective owner

Related posts about apache

Related posts about mod-rewrite