js 實現 http 強制重定向至 https
var reg = /^(192.168.1.)/; if(window.location.hostname !== 'localhost' && !reg.test(window.location.hostname)) { // 判斷非本地server時 http強制轉換成https var targetProtocol = "https:"; if (window.location.protocol != targetProtocol) window.location.href = targetProtocol + window.location.href.substring(window.location.protocol.length); }