- 
      
- 
        Save konklone/9968713 to your computer and use it in GitHub Desktop. 
| <script> | |
| var host = "YOURDOMAIN.github.io"; | |
| if ((host == window.location.host) && (window.location.protocol != "https:")) | |
| window.location.protocol = "https"; | |
| </script> | 
@mikeumus "Always uses https" is equivalente to the 301 redirects?
Here is a tutorial about that: https://rck.ms/jekyll-github-pages-custom-domain-gandi-https-ssl-cloudflare/
@mikeumus worked AWESOMELY!!! ~THANK YOU!!!
You must check for http and NOT for https
bad:
window.location.protocol != "https:"
safe:
window.location.protocol === "http:"
Why? Because in webapps wrapped in Electron and NWjs there's no http - it's file: and chrome-extension:
So:
/*global window */
/*jslint browser: true */
(function (root) {
	"use strict";
	var h = root ? root.location.hostname : "",
	p = root ? root.location.protocol : "";
	if ("http:" === p && !(/^(localhost|127.0.0.1)/).test(h)) {
		root.location.protocol = "https:";
	}
}
	("undefined" !== typeof window ? window : this));
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
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?
@hakatashi thanks, saves me the hassle