서버 http 접속시 https로 자동 접속 하기

페이지 정보

작성자 관리자 (115.♡.104.253) 조회 1,741회 작성일 21-08-28 14:36(글 수정: 2023년 09월 24일)

본문

보안서버 SSL을 설치하면 웹 접속 주소가 https로 됩니다.

그래서 http로 접속도 https로 접속 되게 설정을 해 줄 필요가 있는데요.

아래와 코드를 .htaccess 파일을 만들어 서버 최상위 폴더에 올리면 됩니다.

 

1) .htaccess 파일 생성

 

[code]

<IfModule mod_rewrite.c>

RewriteEngine On 

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>

[/code]

 

 

2) 코드 추가하기

index.php 파일 상단에 아래 코드를 추가하면 됩니다.

[code]

    if(!isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == ""){

    $redirect = "https://".$_SERVER['HTTP_HOST'].$_SERVER['REQUEST_URI'];

    header("Location: $redirect");  

    }

[/code]

 

 

3) 자바스크립트 이용

[code]

<script>

if(window.location.protocol == "http:"){

window.location.protocol = "https:";

}

</script>

[/code]




댓글목록

등록된 댓글이 없습니다.

사이트안내 | 서비스 이용약관 | 개인정보 처리방침 |
마이링크 | 후원안내 | FAQ | Admin
TOP