.htaccess 리디렉션 http를 https로
이전 URL ( www1.test.net
) https://www1.test.net
이 있는데 내 사이트에 SSL 인증서를 구현하고 설치 한 것으로 리디렉션하고 싶습니다 .
이것은 내 이전 파일입니다 .htaccess
.
RewriteEngine On
RewriteRule !\.(js|gif|jpg|png|css|txt)$ public/index.php [L]
RewriteCond %{REQUEST_URI} !^/public/
RewriteRule ^(.*)$ public/$1 [L]
.htaccess
URL이 자동으로 리디렉션되도록 파일을 구성 하려면 https
어떻게 해야 합니까?
감사!
2016 업데이트
이 답변이 주목을 받으면서 가상 호스트를 사용하여 더 권장되는 방법을 힌트하고 싶습니다. Apache : Redirect SSL
<VirtualHost *:80>
ServerName mysite.example.com
Redirect permanent / https://mysite.example.com/
</VirtualHost>
<VirtualHost _default_:443>
ServerName mysite.example.com
DocumentRoot /usr/local/apache2/htdocs
SSLEngine On
# etc...
</VirtualHost>
이전 답변, ssl-port가 80으로 설정되어 있지 않다는 점을 감안할 때 이것은 작동합니다.
RewriteEngine on
# force ssl
RewriteCond %{SERVER_PORT} ^80$
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [L,R]
이것이 첫 번째 재 작성 규칙이어야합니다.
편집 : 이 코드는 다음을 수행합니다. RewriteCond (ition)은 요청의 ServerPort가 80인지 확인합니다 (기본 http-port입니다. 다른 포트를 지정한 경우 조건을 조정해야합니다). 그렇다면 전체 URL을 일치시키고 (.*)
https-url로 리디렉션합니다. %{SERVER_NAME}
특정 URL로 대체 될 수 있지만 이렇게하면 다른 프로젝트의 코드를 변경할 필요가 없습니다. %{REQUEST_URI}
는 TLD (최상위 도메인) 뒤의 URL 부분이므로 사용자가 온 곳으로 리디렉션되지만 https로 리디렉션됩니다.
다음을 사용하여 내 도메인의 모든 페이지를 http에서 https로 성공적으로 리디렉션합니다.
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
리디렉션을 사용하여 301 'permanently moved'
리디렉션되므로 SEO 순위를 전송하는 데 도움이됩니다.
302 'temporarily moved'
변경 사항을 사용하여 리디렉션하려면[R=302,L]
프록시 사용자가 아닌 www 및 https, 프록시에 가장 적합합니다.
RewriteEngine On
### WWW & HTTPS
# ensure www.
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# ensure https
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteCond %{HTTPS} off
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
### WWW & HTTPS
다음 코드로 https를 강제합니다.
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
HTTPS / SSL 연결이로드 밸런서에서 종료되고 모든 트래픽이 포트 80의 인스턴스로 전송되는 경우 다음 규칙이 작동하여 비보안 트래픽을 리디렉션합니다.
RewriteEngine On
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
mod_rewrite
모듈이로드 되었는지 확인하십시오 .
리디렉션하는 가장 좋은 방법을 검색하면서 다음을 찾았습니다 (html5boilerplate에서 제공됨).
# ----------------------------------------------------------------------
# | HTTP Strict Transport Security (HSTS) |
# ----------------------------------------------------------------------
# Force client-side SSL redirection.
#
# If a user types `example.com` in their browser, even if the server
# redirects them to the secure version of the website, that still leaves
# a window of opportunity (the initial HTTP connection) for an attacker
# to downgrade or redirect the request.
#
# The following header ensures that browser will ONLY connect to your
# server via HTTPS, regardless of what the users type in the browser's
# address bar.
#
# (!) Remove the `includeSubDomains` optional directive if the website's
# subdomains are not using HTTPS.
#
# http://www.html5rocks.com/en/tutorials/security/transport-layer-security/
# https://tools.ietf.org/html/draft-ietf-websec-strict-transport-sec-14#section-6.1
# http://blogs.msdn.com/b/ieinternals/archive/2014/08/18/hsts-strict-transport-security-attacks-mitigations-deployment-https.aspx
Header set Strict-Transport-Security "max-age=16070400; includeSubDomains"
아마도 2017 년에 누군가를 도울 것입니다! :)
.htaccess 파일에이 코드를 삽입하십시오. 그리고 그것은 작동합니다
RewriteCond %{HTTP_HOST} yourDomainName\.com [NC]
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://yourDomainName.com/$1 [R,L]
리디렉션에도 문제가있었습니다. 나는 Stackoverflow에서 제안 된 모든 것을 시도했습니다. 내가 찾은 한 가지 사례는 다음과 같습니다.
RewriteEngine on
RewriteBase /
RewriteCond %{HTTP:SSL} !=1 [NC]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
.htaccess 파일 끝에이 코드를 추가하십시오.
RewriteEngine on
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
.htaccess 상단에 다음을 추가합니다.
RewriteEngine On
RewriteCond %{ENV:HTTPS} !=on
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
참고 URL : https://stackoverflow.com/questions/13376219/htaccess-redirect-http-to-https
'Development Tip' 카테고리의 다른 글
클래스 경로에서 파일 인스턴스로 파일을로드 / 참조하는 방법 (0) | 2020.11.02 |
---|---|
Ruby 배열에서 동일한 문자열 요소를 계산하는 방법 (0) | 2020.11.02 |
FIQ와 IRQ 인터럽트 시스템의 차이점은 무엇입니까? (0) | 2020.11.02 |
angular.js 배열에서 요소 / 노드를 제거하는 방법 (0) | 2020.11.02 |
클릭시 EditText를 지우는 방법은 무엇입니까? (0) | 2020.11.02 |