Back to writing
미분류 1 min read HYEONG HWAN, MUN

Apache .htaccess 도메인 컨트롤하기 (www , https)

# 원하는 동작의 주석을 제거하면 동작한다.

.htaccess 파일에 아래의 내용을 넣으면 된다.

이미 .htaccess 파일이 있고 무엇인가 쓰여져 있다면, 그 파일의 맨 밑에 추가해 넣으면 된다.

 

[code language="bash"]

<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>

[/code]

 

Filed under