Skip to content

Instantly share code, notes, and snippets.

@aripalo
Last active February 1, 2016 22:04
Show Gist options
  • Save aripalo/e8205c09e19a10ea2649 to your computer and use it in GitHub Desktop.
Save aripalo/e8205c09e19a10ea2649 to your computer and use it in GitHub Desktop.
(function(w) {
try {
var isHttps = w.location.protocol === "https:";
var hasSniSupport = true;//we default to true
var ua = window.navigator.userAgent;
var isInternetExplorerOnWinXpOrOlder = /MSIE.*Windows\s?((NT)?\s?(([0-5]\.\d))|XP|98|95|NT;)/i.test(ua);
var isAndroid3XorOlder = /Android [0-3]\./i.test(ua);
var isSymbian = /(SymbianOS|Series40|Series60)/i.test(ua);
var isBlackBerry = /BlackBerry/i.test(ua);
if(isInternetExplorerOnWinXpOrOlder || isAndroid3XorOlder || isSymbian || isBlackBerry) hasSniSupport = false;
if(!isHttps && hasSniSupport) {
//alert('Browser probably supports SNI, will "soft redirect" to secure https site');
w.location.href = "https:" + w.location.href.substring(w.location.protocol.length);
}
} catch(e) {
//alert('Something went wrong with SNI "soft redirect": '+e.message)
}
}(window));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment