1) s/http/https/ の置換
まずソースに書かれたhttp://の部分をhttps://に置換します。ただし、外部スクリプトの一部はhttpでしか動かないものもあるので注意。
次に、<head>内に以下を追記。環境変数はjekyllのものです。
head.html
<link rel="canonical" href="{{ site.url }}{{ page.url }}" />
jekyllの場合は、設定ファイルも例外なくhttpの部分はhttpsに書き換えます。
_config.yml
site.url = https://syui.github.io
2) http > httpsへのリダイレクト処理
次に、httpをhttpsにリダイレクトする処理をjavascriptで書きます。以下は、jekyllでの記述の仕方です。
head.html
<script type="text/javascript">
{% if site.enforce_ssl %}
var enforce = "{{ site.enforce_ssl }}";
if ((enforce == window.location.host) && (window.location.protocol != "https:"))
window.location = window.location.toString().replace(/^http:/, "https:");
{% else %}
var host = "syui.github.io";
if ((host == window.location.host) && (window.location.protocol != "https:"))
window.location.protocol = "https";
{% endif %}
</script>
_config.yml
site.enforce_ssl = syui.github.io
参考
enforce SSL on production domain
- EV SSL
ついでに関係ありませんがEV SSLの話をします。これを導入すると、アドレスバーが緑色になります。FirefoxやChromeなど。
SSLサーバ証明書には、信頼性の高い順に、「EV SSL証明書」「企業認証(OV)証明書」「ドメイン認証(DV)証明書」という種類があります。
これらは、SSL証明書を購入して登録しなければなりません。
GeoGetSSLがおすすめらしいです。
以下の記事が登録までの手順を詳しく説明してくれています。