Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
add comment

migrated from serverfault.com Feb 21 '11 at 21:41

This question came from our site for professional system and network administrators.

1 Answer

I'm pretty sure you can do this with straight mod_rewrite rules (using a rewriteCond on HTTP_HOST), but from a configuration-management standpoint it may be easier to take a different tack: I assume you're running each SSL site on its own IP address (because SNI support isn't quite universal yet, though getting close). In this case I would go for the easy solution and set up virtual hosts for each IP (1.2.3.4:80) that forward to the SSL version exactly as you have above.

If you're relying on SNI (everyone is on one IP) you can do the same thing with a NameVirtualHost on port 80...

share|improve this answer
1  
Great answer. First off, for reminding me that every SSL host needs its own IP address. This could prove sticky if we want to scale to hundreds or thousands of users. I'd also never heard of SNI, but my research indicates it's impractical given the propensity of Windows XP clients still hitting our server in gut-wrenching number. Looks like I need to do some additional thinking about this. Thanks for your help! –  Aaron Vegh Feb 18 '11 at 16:49
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.