강제로 https로 접속하도록 하기 (.htaccess 수정)

http로 들어온 사람들을 https로 강제로 들어오게 하고 싶다면? .htaccess 파일을 편집하면 된다.

아래는 https://blog.lael.be/post/1130 에서 가지고 온 코드이다. 주석을 떼서 사용하면 된다.

<IfModule mod_rewrite.c>
RewriteEngine on
 
RewriteRule ^ - [E=protossl]
RewriteCond %{HTTPS} on
RewriteRule ^ - [E=protossl:s]
 
# https 강제이동.
# RewriteCond %{HTTPS} !=on
# RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
# www 강제로 붙이기.
# RewriteCond %{HTTP_HOST} .
# RewriteCond %{HTTP_HOST} !^www\. [NC]
# RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 
# www 가 붙어있으면 떼기.
# RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
# RewriteRule ^ http%{ENV:protossl}://%1%{REQUEST_URI} [L,R=301]
 
</IfModule>

익명에 답글 남기기 응답 취소

이메일 주소는 공개되지 않습니다. 필수 항목은 *(으)로 표시합니다

Scroll to top