簡體   English   中英

重定向到安全服務器(https)

[英]Redirection to Secured Server (https)

我無權訪問.htaccess文件,因此我在JavaScript下面使用從http重定向到https並附加www。

 if(window.location.protocol != 'https:') { location.href = location.href.replace("http://", "https://www."); } 

問題在於,當用戶輸入http://www.example.com時 ,它將重定向到https://www.www.example.com

請幫助我解決問題。

嘗試這個:

if(window.location.protocol != 'https:') {
  location.href = location.href.replace("http://", "https://"); // <-- removed www.
}

只需刪除www. 避免重復

甚至是這樣,因為您只需要切換url的開頭:

if(window.location.protocol != 'https:') {
      location.href = location.href.replace("http", "https");
}

您應該將服務器設置為接受www.example.com或僅接受example.com ,那么用戶是否添加了www無關緊要

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM