🖥️프론트엔드/HTML | CSS | JAVASCRIPT

자바스크립트 - http를 https로 리다이렉트

Janger 2023. 5. 18. 16:58
728x90

 

if (window.location.protocol != "https:") {
    window.location.href = "https:" + window.location.href.substring(window.location.protocol.length);
}

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

 

 

출처: 

https://greendreamtrre.tistory.com/672

 

Javascript (자바스크립트) HTTP 접속 시 HTTPS로 리다이렉트

보통은 톰캣 서버 설정 등에서 자동으로 리다이렉트 시키도록 하지만 각 페이지마다 자바스크립트로 처리하거나 추가 검증을 시켜켜줄 수 있다. if (window.location.protocol != "https:") { window.location.hre

greendreamtrre.tistory.com

 

728x90