查看單個文章
  #1  
舊 2015-05-15, 01:17 PM
spline88 的頭像
spline88 spline88 目前離線
進階會員
 
註冊日期: 2011-10-21
文章: 229
預設 將 http 自動轉成 https

由於搜尋引擎對於 https 有較大的加分, 於是我申請了 SSL

可是搜尋引擎上面收錄的網址仍然是 http

我自己寫了一小段程式, 放在原本的首頁前,

就可以將連進來的 http 自動改成 https

( 前提 : 你的網址必須有ssl )

<script type='text/javascript'>
var url = document.location.href;
var len = url.length;
var http = url.substring(0,5);
if (http != "https") {
var url = "https://" + url.substring(7,len);
window.location.replace(url);
}
</script>

範例請看 http://fatew.com , 會自動變成 https://fatew.com

網頁按右鍵 > 檢視原始檔 !!

希望這樣能提高網站在搜尋引擎的排名.
回覆時引用此篇文章