2014-10-21 7 views
1

Google 코드는 두 개의 다른 서버에서 실행됩니다. 하나는 https가 활성화되어 있고 다른 하나는 ("유산") 않습니다. SSL 서버에서만 https를 강제 실행하려고합니다..htaccess http -> https 재 작성 규칙으로 인한 리디렉션 루프

다음 코드를 추가했지만 리디렉션 루프가 발생했습니다. 다음은

#Force SSL for everyone but legacy production 
RewriteCond %{HTTP_HOST} !legacy\.site\.com 
RewriteCond %{HTTPS} !=on 
#RewriteCond %{SERVER_PORT} !=443 #<--this also causes redirect loop 
#RewriteCond %{REQUEST_SCHEME} != https #<--this causes a 500 error! 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 

(나는이 문제를 생각하지 않습니다하지만 난 완성도를 포함하고 있습니다) 다음입니다 :

#gzip 
AddOutputFilterByType DEFLATE text/plain 
AddOutputFilterByType DEFLATE text/html 
AddOutputFilterByType DEFLATE text/xml 
AddOutputFilterByType DEFLATE text/css 
AddOutputFilterByType DEFLATE application/xml 
AddOutputFilterByType DEFLATE application/xhtml+xml 
AddOutputFilterByType DEFLATE application/rss+xml 
AddOutputFilterByType DEFLATE application/javascript 
AddOutputFilterByType DEFLATE application/x-javascript 


RewriteEngine on 
RewriteCond $1 !^(index\.php|public|robots\.txt) 
RewriteRule ^(.*)$ /index.php/$1 [L] 

이유는 무엇입니까? https://blog.heroku.com/archives/2012/5/3/announcing_better_ssl_for_your_app

+0

'legacy.site.com'에 가지 않는 한이 반복은 안될까요? 어떤 가상 호스트가 이것입니까? 루프를 가져올 때 사용할 사이트의 이름은 무엇입니까? 'site.com'? 'subdomain.site.com'? – arco444

+0

.htaccess에 더 많은 규칙이 있습니까? – anubhava

+0

@ arco444 두 번째 조건이 실패해야 함을 의미하는'https'로 리다이렉트하므로 루핑을 계속해야한다고 생각하지 않습니다. 루프를 가져 오는 URL은'new.site.com'입니다. – emersonthis

답변

2

많은 감사 ...

을 그것은 내가 발견 리디렉션 루프가 SSL이 Heroku가 삼나무 스택 응용 상류 종료 사실의 결과 밝혀 . 즉, 트래픽의 마지막 구간은 거의 https가 아니므로 일반 기술은 영원히 리디렉션 루프를 리디렉션합니다.

(Heroku에서)이 문제를 해결하는 방법은 특별한 사용자 정의 헤더 X-Forwarded-Proto에 RewriteCond를 추가하는 것입니다. 그럼이 작품은 :

##Force SSL for everyone but legacy production 
RewriteCond %{HTTP_HOST} !legacy\.site\.com 
RewriteCond %{HTTPS} !=on 
RewriteCond %{HTTP:X-Forwarded-Proto} !https 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
+0

잘 정리 된이 작업을 마쳤습니다. – arco444

1

서버가 HTTPS 변수를 설정되지 않을 수 있습니다

업데이트 서버가 SSL "다시 돼지"를 사용하는 Heroku가 삼나무 앱입니다. SERVER_PORT를 사용해보십시오 : @anubhava와 사려 깊은 의견 @의 arco444에

RewriteCond %{HTTP_HOST} !^legacy\.site\.com$ 
RewriteCond %{SERVER_PORT} !=443 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE] 
+1

나는 이것을 시도하고 그것은 작동하지 않았다. 루프를 계속 리디렉션합니다. 질문에서 코드를 업데이트하여 내가 한 일을 보여줄 것입니다. – emersonthis

+0

Firebug를 열고 브라우저에서'http : // domain.com /'을 방문하여'인터넷 '탭에서 무엇을 얻었는지 확인하십시오. – anubhava

+1

301 개의 리디렉션이 많이 있습니다. "initiator"필드는'https : // ...'를 보여줍니다. – emersonthis