What is the most efficient code to detect and redirect SNI supported browsers?

.htaccess, sni, ssl

Solution

The below code should work

Options -Indexes +FollowSymLinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^mywebsite.com$
RewriteCond %{HTTPS} (on|off)
RewriteRule ^(.*)$ http://www.mywebsite.com/$1 [R=302,L]

RewriteCond %{HTTPS} off
RewriteCond %{HTTP_USER_AGENT} !MSIE\s6
RewriteCond %{HTTP_USER_AGENT} !Windows\sNT\s5
RewriteCond %{HTTP_USER_AGENT} !^(.*.symbian.*) [NC]
RewriteCond %{HTTP_USER_AGENT} !^(.*.blackberry.*) [NC]
RewriteRule ^(.*)$ https://www.mywebsite.com/$1 [R=302,L]

Here we are neglecting most of the browsers which does not support SNI and hence for them only the http version would be loaded.

Problem

Say, I have a website `mywebsite.com`, hosted using Apache Httpd. Now what I want is that whenever any user types `mywebsite.com` or `www.mywebsite.com` and if the browser supports SNI then it should redirect to `https://www.mywebsite.com` else redirect to `http://www.mywebsite.com`. So, what is the most efficient way to achieve it ?

Original source