2014-11-23 3 views
1

.htaccess 파일을 사용하여 특정 조건이 존재하면 일종의 규칙 루프가 생성됩니다..htaccess 내부 리디렉션 문제

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC] 
RewriteRule ^(.+)/?$ /%1.php?o=$1 [L,NC,QSA] 

RewriteCond %{HTTP_HOST} ^(.*)\.example\.com$ [NC] 
RewriteRule ^$ /%1.php [L,NC,QSA] 
</IfModule> 

일반적으로 어떤이가하는 것은 :

test.example.com -> example.com/test.php 
test.example.com/test2 -> example.com/test.php?o=test2 

그게 벌금, "테스트"하위 도메인 부분의 포인트가 존재하지 않는 파일에, 나는 내부 리디렉션 오류받을 때를 제외하고 여기에 문제의 코드는 , 구체적으로 다음과 같습니다.

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace., referer: [retracted] 

도움이 되었습니까?

답변

1

/test.php에 대해 RewriteCond %{REQUEST_FILENAME} !-f이 계속 적용되므로 /test.php이없는 경우 루핑이 발생합니다.

당신은 루프를 방지하기 위해이 코드를 사용할 수 있습니다

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] 
RewriteRule ^(.*)$ http://%1/$1 [R=301,L] 

# don't redirect after one internal redirect 
RewriteCond %{ENV:REDIRECT_STATUS} .+ 
RewriteRule^- [L] 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC] 
RewriteRule ^(.+?)/?$ /%1.php?o=$1 [L,QSA] 

RewriteCond %{HTTP_HOST} ^([^.]+)\.example\.com$ [NC] 
RewriteRule ^$ /%1.php [L] 
</IfModule> 
+1

감사합니다,이 – lemondrop

+0

은 다행이 일하지 않고 그것 (이 꽤 확실한 대답 있다면 정말 미안 이해 htaccess로와 정말 좋은 아니에요) 일 그렇게 분명하지 않았다 :) – anubhava