TIP! HTTPS on main domain and HTTP sub domain

Ok, so this is a tip!

On my site, lets call it "example.com", i have a simple ssl cert installed, for use with my main domain. But i ran into an issue with my sub domains, demo.example.com, where i got a warning about the ssl certificate, which is normal since the ssl certificate is only usable for the main domain. So the question rose, how to get automagically https on my main domain, and http on the subdomains...?

After hours of trial and error, chatting with hoster support etc, i found this solution for .htaccess:

RewriteEngine on
# Redirect main domain and www to HTTPS
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} =example.com [or]
RewriteCond %{HTTP_HOST} =www.example.com
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Redirect wildcard subdomains to HTTP
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^(.+)\.example\.com$ [NC]
RewriteCond %{HTTP_HOST} !=www.example.com
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

And this works perfectly, at least for me and my setup, which is:
Wordpress Multisite activated with subdomain support, and a wildcard subdomain (*.example.com).

I have seen other struggle to get this working in the forums here, so i hope this can be help full for some.