Skip to content

Instantly share code, notes, and snippets.

@Nils-van-Kleef
Created December 16, 2016 14:50
Show Gist options
  • Save Nils-van-Kleef/5a649a1a54b9b81b079ee24ff1f6fa34 to your computer and use it in GitHub Desktop.
Save Nils-van-Kleef/5a649a1a54b9b81b079ee24ff1f6fa34 to your computer and use it in GitHub Desktop.
Redirect: Strips href up to "www.", then Prepends https://www. and then executes redirect
/* _optimizely_redirect=http://www.example.com */
var toPrepend = "https://www.";
var hrefPostWWW = window.location.href.split("//")[1].replace("www.","");
var newHref = toPrepend.concat(hrefPostWWW);
window.location.replace(newHref);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment