[CentOS 6.8] Apache 2.2.x 에서 http URL을 https 로 자동 변경 정보
[CentOS 6.8] Apache 2.2.x 에서 http URL을 https 로 자동 변경관련링크
본문
방법1. mod_rewrite
happyjung.com 으로 들어왔을때 mod_rewrite 가 모듈에 올라가 있고 HTTPS로 요청한것이 아니라면 강제로 redirect 시키는 방법입니다.
[R,L] 에서 R은 강제로 redirect 시킨다는 뜻 입니다. http status code에 의해 분기할 수 있습니다.
L은 마지막 RewriteRule 이라는 뜻 입니다. 이후의 RewriteRule은 모두 무시됩니다.
만약 해당 설정 아래에 또다른 RewriteRule이 필요하다면 L를 빼면 됩니다.
# vi /etc/httpd/conf/httpd.conf
...
<VirtualHost *:80>
DocumentRoot /home/happyjung/public_html
ServerName happyjung.com
ServerAlias www.happyjung.com
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteLog logs/rewrite_log
RewriteCond %{HTTPS} off
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
</IfModule>
</VirtualHost>
방법2. mod_redirect
happyjung.com 으로 들어왔을때 Location이 / (root) 일 경우
match 되는 모든것들을 $1 변수를 이용하여 redirect 시키는 방법 입니다.
# vi /etc/httpd/conf/httpd.conf
...
<VirtualHost *:80>
DocumentRoot /home/happyjung/public_html
ServerName happyjung.com
ServerAlias www.happyjung.com
<Location />
RedirectMatch /(.*)$ https://www.happyjung.com/$1
</Location>
</VirtualHost>
참고자료
http://taesachi.com/?p=6
http://www.mimul.com/pebble/default/2010/07/19/1279542240000.html
2
댓글 3개
저에게는 너무 귀한 팁(Tip)입니다. 기억도 하나 안 나고
아무것도 모르겠더라고요. ㅡㅡ 열심히 배우겠습니다! 고맙습니다.
진짜 필요합니다. 사실 정보는 굳이 외워야 하나? 싶어요.
잘 정리하여 빠르게 찾기가 더 낫지 않을까?
이보다는 본질에 가까운 고민을 해야 하는 것 아닌가? 싶죠.
그런 의미에서 저도 죽어라 저장하겠습니다. ^^ 감사합니다!