Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a site that has an SSL certificate on a subdomain, let's call it https:// ssl.maindomain.com. I want to redirect all https requests on https:// maindomain.com to https:// ssl.maindomain.com, while still keeping all http requests on http:// maindomain.com.

Is this even possible? I've googled and nothing really came up.

(The spaces in the protocols are because I cannot post hyperlinks)

Thanks, Luke

edit: Figured it out. This did the trick.

RewriteCond %{HTTPS} on
RewriteRule ^(.*)$ https://ssl.maindomain.com%{REQUEST_URI} [R,L]
share|improve this question
    
Please answer to yourself and check it as valid –  Olivier Pons Mar 13 '12 at 8:36

1 Answer 1

up vote 1 down vote accepted

Use the rewrite module in apache ... the lines you need to place into the vhost for maindomain.com would look something like this (please test first, this is untested):

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) https://ssl.maindomain.com$1

Basically, turn on the engine (line 1), if the the https is "on" (line 2) execute the next line: rewrite the url to ssl main domain (line 3). The third line would work like this:

https://maindomain.com/mypage to https://ssl.maindomain.com/mypage

https://maindomain.com/ to https://ssl.maindomain.com/

This would only trigger on the condition (RewriteCond) that https is on. When https is off, i.e., http, your traffic should continue go to http://maindomain.com/

Try it out in a test server before running this in production in case this interferes with some other rules. HTH.

share|improve this answer

Your Answer

 
discard

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.