Last active
January 2, 2024 15:09
-
-
Save konklone/9968713 to your computer and use it in GitHub Desktop.
Force a quick redirect to HTTPS on Github Pages for your domain (and only your domain)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<script> | |
var host = "YOURDOMAIN.github.io"; | |
if ((host == window.location.host) && (window.location.protocol != "https:")) | |
window.location.protocol = "https"; | |
</script> |
shorter condition:
if (window.location.href.match("http://MYDOMAIN")) window.location.protocol='https:'
Note that the MYDOMAIN can even be partial (e.g. to support both domain.github.io
, domain.com
, whatever) or use more complex regex matching. The important thing is to avoid the test domains (http://localhost, http://127.0.0.1, etc)
but where should i add the code. into my index.html?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In this article, explain how to work HTTPS URL for your custom domain if you are using cloudflare.
https://infinitbility.com/always-use-https-url-using-cloudflare