htaccess를 사용하여 http URL을 https URL로 리디렉션
Dec 28 2019
htaccess 파일에서 아래 코드를 사용하여 www를 www가 아닌 도메인으로 리디렉션하고 요구 사항은 아래와 같습니다.
RewriteCond %{HTTPS} off
RewriteCond %{HTTP_HOST} ^www\.example\.com$ RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
RewriteCond %{HTTPS} on
RewriteCond %{HTTP_HOST} ^www\.example\.com$ RewriteRule ^/?$ "https\:\/\/example\.com\/" [R=301,L]
요구 사항 :
WWW에서 비 WWW로
- http://www.example.com ...에 https://example.com
- https://www.example.com ...에 https://example.com
비 https URL에서 https URL로
- http://example.com ...에 https://example.com
http URL이 아닌 다른 모든 페이지에서 https URL로
- http://example.com/blog/7-best-places-to-visit ...에 https://example.com/blog/7-best-places-to-visit
결과:
예상대로 잘 작동합니다.
& 3이 작동하지 않고 사용자가 브라우저에 직접 입력하면 http URL이 유지됩니다. https url로 업그레이드해야합니다.
코드가 godaddy 공유 호스팅에서 실행 중입니다. 어떤 도움이라도 대단히 감사하겠습니다. 궁금한 점이 있으면 언제든지 알려주세요.
답변
Wiimm Dec 27 2019 at 23:55
나는 이것을 사용한다 :
RewriteEngine On
# the following line is only needed, if HTTP and HTTPS share the same config
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !^/.well-known/
RewriteRule .* https://wiimmfi.de$0 [R=301,L]
/.well-known/Let 's encrypt 인증서 업데이트를 제외 했습니다.
<directory>.htaccess 내부 :
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_FILENAME} !^.well-known/
RewriteRule .* https://wiimmfi.de/$0 [R=301,L]