RadarURL

조회 수 7 추천 수 0 댓글 0
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄
?

단축키

Prev이전 문서

Next다음 문서

크게 작게 위로 아래로 댓글로 가기 인쇄

1. 개요

Apache에서 HTTP/HTTPS 프로토콜 별로 리다이렉트/라라이트 하는 방법.

 

2. 활용

RewriteCond %{HTTPS} on/off 설정을 이용하여 프로토콜 별로 처리할 수 있다.

 

Rewrite를 추가하는 부분에서 SSL 인증서를 사용하고 있다면 [P] 옵션을 사용하기 때문에  (P=Proxy)

SSLProxyEngine On 설정을 추가해줘야 한다.

 

Proxy를 사용하지 않아도 될 경우에는 [P,R,L] -> [R=301,L] 사용

 

ㅁ HTTP를 HTTPS로 리다이렉트 

   <IfModule mod_rewrite.c>

        RewriteEngine On

        RewriteCond %{HTTPS} off

        RewriteRule (.*) https://%{HTTP_HOST}/$1 [P,R,L]

   </IfModule>

 

 

ㅁ  HTTPS를 HTTP로 리다이렉트

 SSLProxyEngine On    => SSL 인증서를 이용하고 있다면 넣어줘야 한다.

   <IfModule mod_rewrite.c>

        RewriteEngine On

        RewriteCond %{HTTPS} on

        RewriteRule (.*) http://%{HTTP_HOST}/$1 [P,R,L]

   </IfModule>

 

 

ㅁ HTTP/HTTPS를 고려하여, 받은 URL 그대로 리다이렉트.

 SSLProxyEngine On  => SSL 인증서를 이용하고 있다면 넣어줘야 한다. 

   <IfModule mod_rewrite.c>

        RewriteEngine On

        RewriteCond %{HTTPS} on

        RewriteRule .* https://%{HTTP_HOST}/$1 [P,R,L]

        RewriteCond %{HTTPS} off

        RewriteRule (.*) http://%{HTTP_HOST}/$1 [P,R,L]

   </IfModule>

 

 

ㅁ 

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}%/$1 [L,R=301]

 

1)  RewriteCond %{HTTPS} off

    - HTTP로 접속 된 경우,

 

2) RewriteRule의 [R,L]

[L]은 정의의 마지막 줄(Last)을 의미함. 이 줄 아래의 RewriteRule은 모두 무시. 가장 마지막 행에 씀.

[L]을 쓰지 않아도 동작은 함.

[R]은 리다이렉트 실행함. 

 

 

=============================================================================[apache] http -> https로 리다이렉트 처리

 

ㅁ httpd-vhosts.conf 수정

RewriteEngine On

RewriteCond %{HTTPS} off

RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

 

1. RewriteEngine On

   - RewriteEngine 활성화

 

2. RewriteCond %{HTTPS} off (or !=on)

   - 조건 : HTTPS 가 아니면   

 

3. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

   - R=301은 301 리디렉션이라는 뜻이고, L은 마지막이라는 뜻입니다.

     L은 반드시 필요한건 아니지만 R=301은 반드시 해줘야 합니다. 저게 빠지면 302 리디렉션이라고 감지합니다.

     (301은 영구적인 이동, 302는 일시적인 이동)

 

ㅁ 유사한 처리 방식

Redirect permanent / https://hanajava.net

 

 

참고 : https://httpd.apache.org/docs/2.4/ko/mod/mod_alias.html 

 

(https://%{HTTP_HOST}/$1 이랑 https://%{HTTP_HOST}%{REQUEST_URI}  둘 다 잘 작동함)

https://%{HTTP_HOST}/$1 (O - 올바른 설정)

https://%{HTTP_HOST}$1 (X - 잘못된 방식) : 이렇게 설정하면 최상위 도메인까지만 되고 그 이하 페이지는 리다이렉트가 안됨.

 

 

 

4. 그 외

https://(도메인)\.(도메인)/$1 [R=301,L] 이런 방식이 있는데, 이것도 잘 작동합니다.

 

(.*)이 아니라 ^(.*)$라고 되어 있는것도 많은데 별 차이는 없다고 하네요

 

Redirect permanent / https://example.com

 

 

ㅁ NGINX 설정 방법

# Redirect non-https traffic to https

if ($scheme != "https") {

return 301 https://$host$request_uri;

} #

 

 

ㅁ 

​[]

 

 

출처 : https://blog.naver.com/hanajava/221963448277

?

공부 게시판

공부에 도움되는 글을 올려주세요.

  1. [공지] 공부 게시판 입니다.

    Date2003.08.18 By처누 Views928143
    read more
  2. [apache] HTTP/HTTPS 리다이렉트(Redirect/Rewrite) 하는 방법

    Date2025.09.11 Category웹서버,WAS ByJaeSoo Views7
    Read More
  3. http를 https로 리다이렉트하는 여러가지 방법

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views7
    Read More
  4. SSL인증서 없이 HTTPS에서 HTTP로 되돌리기

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views8
    Read More
  5. [SSL] win-acme, Let's encrypt로 무료 SSL 인증서 발급

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views6
    Read More
  6. [SSL] Windows 10에서 Let's Encrypt로 SSL 인증서 무료 발급받기

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views6
    Read More
  7. 무료로 https SSL/TLS 인증서를 발급받을 수 있는 인증 기관

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views6
    Read More
  8. 아파치 서버에 https SSL 인증서 적용하는 방법 (apache httpd)

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views6
    Read More
  9. 아파치2(Apache2) SSL HTTPS 적용하기

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views6
    Read More
  10. 아파치 웹서버에 멀티 도메인에 대한 80, 443 포트 설정하는 방법

    Date2025.09.10 Category웹서버,WAS ByJaeSoo Views12
    Read More
  11. 용량 산정 (동시 접속자 계산)

    Date2016.05.05 Category웹서버,WAS ByJaeSoo Views1028
    Read More
  12. 아파치 httpd.conf 재시작 없이 설정 적용하기

    Date2016.05.02 Category웹서버,WAS ByJaeSoo Views647
    Read More
  13. Tomcat JVM heap memory set 및 size

    Date2016.03.23 Category웹서버,WAS ByJaeSoo Views706
    Read More
  14. Java 실행 옵션 정리

    Date2016.03.23 Category웹서버,WAS ByJaeSoo Views624
    Read More
  15. [JAVA] 개발환경설정 - 표준프레임워크

    Date2016.01.02 Category웹서버,WAS ByJaeSoo Views792
    Read More
  16. Tomcat 7.x 와 8.x 간의 default configuration 차이

    Date2016.01.02 Category웹서버,WAS ByJaeSoo Views717
    Read More
  17. 톰캣 8 소개

    Date2016.01.01 Category웹서버,WAS ByJaeSoo Views517
    Read More
  18. 리눅스 webalizer를 통한 apache log(웹서버 접속 통계) 분석하기 (추천)

    Date2014.12.25 Category웹서버,WAS ByJaeSoo Views1098
    Read More
  19. 리눅스 아파치 로그 뷰어 webalizer, utf-8로 변환하기

    Date2014.12.22 Category웹서버,WAS ByJaeSoo Views880
    Read More
  20. Webalizer Configuration – Configure Webalizer for SEO

    Date2014.12.22 Category웹서버,WAS ByJaeSoo Views1413
    Read More
  21. Webalizer, AWStats에서 국가 정보 확인하기

    Date2014.12.22 Category웹서버,WAS ByJaeSoo Views854
    Read More
Board Pagination Prev 1 2 3 Next
/ 3


즐겨찾기 (가족)

JAESOO's HOMEPAGE


YOUNGAE's HOMEPAGE


장여은 홈페이지


장여희 홈페이지


장여원 홈페이지


즐겨찾기 (업무)

알리카페 홀릭

숭실대 컴퓨터 통신연구실 (서창진)

말레이시아 KL Sentral 한국인 GuestHouse


즐겨찾기 (취미)

어드민아이디

유에코 사랑회

아스가르드 좋은사람/나쁜사람

JServer.kr

제이서버 메타블로그

재수 티스토리


즐겨찾기 (강의, 커뮤니티)

재수 강의 홈페이지


한소리


VTMODE.COM


숭실대 인공지능학과


숭실대 통신연구실


베너