Hello,
I would love it if I could have an option to force https connections on a static website. A lot of my users have come back to me telling me that my website is not secure…
Hey @ImDaBigBoss,
You can enforce HTTPS on your static site using code.
Before the closing tags, add these lines of code:
<script>
// https://gist.github.com/youngchief-btw/d8c327ef245f2e9998997a41c7b34e70
if (location.protocol === "http:") {
location.replace(window.location.href.replace("http:", "https:"));
}
</script>
(Credit: @youngchief_btw ^_^)
Hope this helps!
2 Likes
Oh thanks so much!
(tho it won’t work if someone disables JavaScipt)
2 Likes
Yes, that is pretty much a limitation. It would be best to enforce HTTPS from the server-side, but in a static site, it isn’t possible.
2 Likes
Thanks for helping people find this really cool gist and giving me credit along with the gist URL!!
2 Likes
No problem!
2 Likes