2016-07-07 2 views
0

아파치 설정 파일에 다음과 같은 Rewrite 코드가 있지만 쿠키가 존재할 때이를 인식 할 수 없습니다. 나는 여기서 여러 가지 대답을 보았지만 어떤 문제를 고치는지를 찾을 수없는 것 같습니다.HTTP_COOKIE RewriteCond Failing

RewriteEngine on 
RewriteCond %{HTTP_COOKIE} ^returnvisitor$ [NC] 
RewriteRule .? - [S=3] 
RewriteRule /index.html /new_visitor.html 
RewriteRule .* - [CO=returnvisitor:yes:.127.0.0.1:1440:/:true:true] 
RewriteRule .? - [S=1] 
RewriteRule /index.html /returning_visitor.html 

업데이트 1 :

예상대로 행동하지 않는 여전히 다음 몇 가지 진전을하지만, 나는이 코드를 수정 한

.

RewriteEngine on 
RewriteCond %{HTTP_COOKIE} returnvisitor=yes [NC] 
RewriteRule .? - [S=3] 
RewriteRule /index.html /new_visitor.html [R] 
RewriteRule .* - [CO=returnvisitor:yes:.127.0.0.1:1440:/:true:true] 
RewriteRule .? - [S=1] 
RewriteRule /index.html /returning_visitor.html [R,L] 

원래 코드는 홈페이지를 리디렉션 것 (즉, index.html되는 기본 페이지)의 두 번째 요청하지만, 지금은 리디렉션 트리거하기위한 URL에 수동 요청 index.html을 가지고 있지만, 적어도이 시간 index.htmlreturning_visitor.html으로 리디렉션되었습니다.

방문자가 new_visitor.html으로 처음 전송 된 후 example.com을 통해 홈페이지에 액세스 할 때 발생하는 리디렉션이 필요하며 이후 방문은 returning_visitor.html으로 리디렉션됩니다. 밖에 나가서 example.com/index.html을 수동으로 입력해야합니다.

+0

귀하의 쿠키는 가치가 없습니까? '^ returnvisitor ='를 대신 사용 하시겠습니까? –

+0

@MarcB 'RewriteRule. * - [CO = returnvisitor : yes : .127.0.0.1 : 1440 :/: true : true]'코드 줄을 사용하여 쿠키를 처음 만들었습니다. 내 브라우저와 쿠키가 제대로 만들어지고 있는지 확인합니다. 단지'RewriteCond'에서 발견되지 않았습니다. 나는 그 상태뿐만 아니라'/^(.*;)? returnvisitor = yes (; *.)? $ /' – defaultNINJA

답변

1

당신은 사용할 수 있습니다

RewriteEngine on 
#First visit 
# if the cookie is not set 
RewriteCond %{HTTP_COOKIE} !returnvisitor=yes$ [NC] 
# serve "/new_visitor.html" 
RewriteRule /index.html /new_visitor.html [R,L] 
#second visit 
#set the cookie "returnvisitor" on any uri 
RewriteRule .* - [CO=returnvisitor:yes:.127.0.0.1:1440:/:true:true] 
#check to see that the cookie is set 
RewriteCond %{HTTP_COOKIE} returnvisitor=yes$ [NC]  
#if so, redirect the index.html to "/returning_visitor.html" 
RewriteRule /index.html /returning_visitor.html [R,L] 

이 당신을 위해 작동하는 방법을 알려주세요.