htaccess를 사용하여 HTTP에서 http로 리디렉션
https://www.example.com 을 http://www.example.com 으로 리디렉션하려고합니다 . .htaccess 파일에서 다음 코드를 시도했습니다.
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]
이 코드는 https://example.com 을 http://www.example.com 으로 성공적으로 리디렉션 합니다. 그러나 https://www.example.com 을 입력 하면 브라우저에 "웹 페이지를 사용할 수 없음"오류가 표시됩니다.
나는 또한 성공하지 않고 다음 두 코드를 시도했습니다
시도 1
RewriteEngine On
RewriteCond %{HTTPS} !=on
RewriteRule ^/(.*):NOSSL$ http://www.example.com/$1 [R=301,L]
시도 2
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
위의 두 시도 모두 실패했습니다. 어떤 제안?
시도 2는 거의 완벽했습니다. 약간 수정하십시오.
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
그러나 웹 사이트에 보안 인증서가없고 공유 호스팅 환경에 있고 웹 사이트가 https를 통해 요청 될 때 "경고"를 받고 싶지 않은 경우 htaccess를 사용하여 리디렉션 할 수 없습니다. 그 이유는 요청이 htaccess 파일로 전달되기 전에 경고 메시지가 트리거되므로 서버에서 수정해야하기 때문입니다. /etc/httpd/conf.d/ssl.conf로 이동하여 가상 서버 443에 대한 부분을 주석 처리하십시오.하지만 호스팅 제공 업체가 그다지 제어 할 수 없을 가능성이 있습니다. 따라서 다른 호스트로 이동하거나 SSL을 구입하여 htaccess가 리디렉션 할 기회를 갖기 전에 경고가 트리거되지 않도록해야합니다.
RewriteEngine On
RewriteCond %{SERVER_PORT} 443
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
다음 규칙을 사용하여 https 에서 http 로 리디렉션 할 수 있습니다 .
RewriteEngine On
RewriteCond %{HTTPS} ^on$
RewriteRule ^(.*)$ http://example.com/$1 [NC,L,R]
설명 :
RewriteCond %{HTTPS} ^on$
HTTPS가 켜져 있는지 확인 (https를 사용하여 요청)
그때
RewriteRule ^(.*)$ http://example.com/$1 [NC,L,R]
모든 요청 ( https://example.com/foo ) 을 http://example.com/foo로 리디렉션합니다 .
$ 1은 RewriteRule 패턴의 정규식의 일부이며 (. +) 에서 캡처 된 모든 값을 포함 합니다. 이 경우 도메인 이름 뒤의 전체 request_uri 모든 것을 캡처합니다.
[NC, L, R]은 플래그이고 NC는 uri 대소 문자를 구분하며 요청에 대문자 또는 소문자를 모두 사용할 수 있습니다.
L 플래그는 currunt 규칙이 일치하는 경우 서버에 다른 규칙의 처리를 중지하도록 지시합니다. 블록에 규칙이 더 많을 때 규칙 충돌을 방지하기 위해 L 플래그를 사용하는 것이 중요합니다.
R 플래그는 외부 리디렉션을 만드는 데 사용됩니다.
The difference between http and https is that https requests are sent over an ssl-encrypted connection. The ssl-encrypted connection must be established between the browser and the server before the browser sends the http request.
Https requests are in fact http requests that are sent over an ssl encrypted connection. If the server rejects to establish an ssl encrypted connection then the browser will have no connection to send the request over. The browser and the server will have no way of talking to each other. The browser will not be able to send the url that it wants to access and the server will not be able to respond with a redirect to another url.
So this is not possible. If you want to respond to https links, then you need an ssl certificate.
RewriteCond %{HTTP:X-Forwarded-Proto} =https
Your code is correct. Just put them inside the <VirtualHost *:443>
Example:
<VirtualHost *:443>
SSLEnable
RewriteEngine On
RewriteCond %{HTTPS} on
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI}
</VirtualHost>
참고URL : https://stackoverflow.com/questions/12999910/https-to-http-redirect-using-htaccess
'Program Tip' 카테고리의 다른 글
unix-파일의 열 수 (0) | 2020.11.13 |
---|---|
Symfony 2에서 모든 요청 매개 변수 얻기 (0) | 2020.11.13 |
녹아웃 바인딩이 실행되기 전에 HTML이 표시되는 것을 방지하는 방법 (0) | 2020.11.13 |
간단한 "Hello World"는 64 비트 컴퓨터에서 10G 가상 메모리가 필요하고 32 비트에서는 1G가 필요합니까? (0) | 2020.11.13 |
Nodemon-파일 제외 (0) | 2020.11.13 |