개발/Linux, System

[Apache2] Rewrite Engine을 이용한 Http Https Redirect

Reimu. 2016. 6. 23. 15:06
반응형

SSL 인증서 설치 후, 기존 http 요청은 더이상 필요가 없기 때문에, http로 들어온 요청을 모두 https로 강제로 Redirect 시키는 방법에 대해 알아 보았다. 


1. mod_rewrite library를 사용하도록 설정한다.

$ a2enmod rewrite


2. 아래와 같은 구문을 설정에 추가한다.

<VirtualHost *:80>
    ...
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
    ...
</Virtualhost>


3. Apache2를 재시작해준다.

$ service apache2 restart


반응형