티스토리 뷰

SSL을 설치를 해도 거의 대부분의 사람들은 URL을 통한 접근을 할 때 HTTP protocol로 입력을 하고 들어온다. 그렇다고 사용자들보고 꼭 우리 사이트는 HTTPS protocol을 사용하니 https://xxxx.xxxx 이렇게 들어오라고 할수는 없다. 이럴때 사용을 하는것이 HTTPS redirection이다. HTTP로 들어온 요청을 HTTPS로 바꿔주는것이다. 웹서버를 Apache를 사용하고 있다고 가정하고 위의 작업을 진행해 보자. 


모든 요청을 HTTP>HTTPS 로 Redirect 하기 

httpd.conf 

<VirtualHost *:80>
        ServerName oingdaddy.sample.com
        DocumentRoot /app/deploy/webstatics/sample/WebContent
        .....

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>

 

 

[R,L] 은 무엇인가? R은 강제 Redirect, L은 Last RewriteRule 이라고 이해하면 된다. 


특정 요청일때만 HTTP>HTTPS 로 Redirect 하기 

httpd.conf

<VirtualHost *:80>
        ServerName oingdaddy.sample.com
        DocumentRoot /app/deploy/webstatics/sample/WebContent
        .....

        RewriteEngine On
        RewriteCond %{HTTPS} off
        RewriteRule ^/login(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
</VirtualHost>

 

/login 으로 들어오는 요청에 대해서만 https로 변경을 하는 방법이다. 

 

끝!

댓글
최근에 올라온 글
최근에 달린 댓글
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31