Recently I've had the need to force HTTPS for some eCommerce sites. After an exhaustive search for a Drupal related answer I just had to test the multitude of solutions I found.

This is what I found to work for two sites running Ubercart SSL.

.htaccess cond/rule does not work - It creates an incorrect redirect

RewriteCond %{HTTPS} !=on
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

PHP code does work! - place it at the top of settings.php

if (!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] !== 'on') {
    if(!headers_sent()) {
        header("Status: 301 Moved Permanently");
        header(sprintf(
            'Location: https://%s%s',
            $_SERVER['HTTP_HOST'],
            $_SERVER['REQUEST_URI']
        ));
        exit();
    }
}