SetEnvIf X-Forwarded-Proto "https" HTTPS=on
RewriteEngine on                                                                                                                        
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP:X-Forwarded-Proto} !https [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]