2011-08-23 7 views
0

아파치 재 작성에 몇 가지 문제점이 있습니다. 내 사이트 전체가 Google지도 API가 포함 된 한 페이지 (visit_us.php)와 별개로 SSL (온라인 상점)을 통해 운영됩니다 (Google은 HTTPS 액세스에 대해 $$$$$을 부과하기 때문에). 이 페이지는 보안되지 않은 컨텐트 (모든 최종 사용자에게 좋지 않은 소리)를 포함 할 때마다 메시지를 표시하므로 포트 80으로 전환하는 간단한 apache 재 작성 규칙을 구현했으며 정상적으로 작동합니다.아파치 재 작성 문제가 있습니다.

RewriteEngine On 

#redirect all http traffic to https, unless visit_us.php is requested 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/visit_us\.php 
RewriteRule ^(.*)$ https://www.myurl.com/$1 [R=301,L] 

#redirect https traffic for visit_us.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

그러나 (만 이상의 HTTP를 작동 할 수 있습니다) 트위터 위젯을 통합에, 난 내가이 간단 할 것이라고 생각 80 포트를 통해 작동 목록에 소셜 네트워킹 페이지를 추가해야 실현 충분히, 그래서, 위의 목록에 social.php 페이지를 추가 :

RewriteEngine On 

#redirect all http traffic to https, unless visit_us.php or social.php is requested 
RewriteCond %{SERVER_PORT} 80 
RewriteCond %{REQUEST_URI} !^/visit_us\.php 
RewriteCond %{REQUEST_URI} !^/social\.php 
RewriteRule ^(.*)$ https://www.myurl.com/$1 [R=301,L] 

#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php 
RewriteCond %{REQUEST_URI} ^/social\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

를 내 사이트에, 내가 명시 적으로 HTTPS가 아니라, HTTP로 연결합니다. 그러나 visit_us.php 페이지에서도 여전히 작동하지만 social.php 페이지는 무시되고 요청은 포트 443에서 끊임없이 끝납니다. 무엇이 잘못 되었나요?

+0

Apache questi ons는 거의 항상이 stackoverflow.com에 대한 오프 주제입니다. 항상 serverfault 또는 웹 마스터 stckexchange 사이트가 있습니다. –

+0

미래를 염두에 두겠습니다. 고마워요. – Stann0rz

답변

2
#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php 
RewriteCond %{REQUEST_URI} ^/social\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

현재 재 작성 조건에 대한 기본 AND 논리를 사용할 수 없습니다 - 대신 OR 논리이어야한다 (일반 영어로 조건을 읽고 당신은 결함를 볼 수 있습니다).

두 가지 방법 :

1. 명시 적으로 OR 논리를 사용하도록 지정 :

#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/visit_us\.php [OR] 
RewriteCond %{REQUEST_URI} ^/social\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 

2는 (사용되는 경우 OR 논리) 하나에 두 개의 재 작성 조건을 병합 :

#redirect https traffic for visit_us.php and social.php to http 
RewriteCond %{SERVER_PORT} 443 
RewriteCond %{REQUEST_URI} ^/(visit_us|social)\.php 
RewriteRule ^(.*)$ http://www.myurl.com/$1 [R=301,L] 
+0

아아, visit_us가 여전히 작동했기 때문에 AND가 기본 연산자라고 생각하지 않았습니다. 그러나 후자는 훨씬 더 적절하고 잘 작동합니다, 팁 덕분에! – Stann0rz