Options +FollowSymLinks
RewriteEngine On
#if we're on the login page (system/index.php) switch to https
RewriteCond %{REQUEST_URI} ^/system/index\.php$
RewriteCond %{QUERY_STRING} !^S=0&C=login&M=auth$
RewriteCond %{QUERY_STRING} ^$
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://www.mydomain.com%{REQUEST_URI} [NS,R,L]
#if we're on the failed login page (system/index.php?S=0&C=login&M=auth) switch to https
RewriteCond %{REQUEST_URI} ^/system/index\.php$
RewriteCond %{QUERY_STRING} ^S=0&C=login&M=auth$
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^ https://www.mydomain.com/system/index.php [NS,R,L]
#if we're on any other page (system/index.php?S=xyz) switch to http
RewriteCond %{REQUEST_URI} ^/system/index\.php$
RewriteCond %{QUERY_STRING} !^S=0&C=login&M=auth$
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{SERVER_PORT} !=80
RewriteRule ^ http://www.mydomain.com/system/index.php [NS,R,L]