Skip to content

Instantly share code, notes, and snippets.

@miguelmota
Created April 16, 2018 23:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelmota/235da9f6492eb78440b8cbf8ea0e3644 to your computer and use it in GitHub Desktop.
Save miguelmota/235da9f6492eb78440b8cbf8ea0e3644 to your computer and use it in GitHub Desktop.
JavasScript redirect to HTTPS
<script>
var url = window.location.href.replace(/http:\/\/(?:www\.)?(mywebsite\.com|otherdomain\.io)/gi, 'https://mywebsite.com');
url !== window.location.href && (window.location.href = url)
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment