2012-06-27 6 views
0

내 학교에 소규모 학부모/교사 소셜 네트워크가 있습니다. 나는 .htaccess 파일을 사용하여 교사 프로파일에 대한 링크를보다 명확하게 만들고 모든 URL에 후행 슬래시를 추가합니다. /teachers/teacher-name/ (때때로) 링크가 /teachers/teacher-name.php.php.php.php.php.php.php.php...으로 리디렉션 될 때이 문제가 발생합니다. 아래는 내 .htaccess 파일입니다. 경우에 따라 Chrome에서 브라우저 캐시를 지우면 임시로 수정됩니다. 정확히 .htaccess 구문을 사용할 수는 없지만 꽤 잘 알고 있습니다. 모든 제안을 부탁드립니다!.htaccess 여러 개의 .php 확장자를 추가하는 리디렉션 루프

RewriteEngine on 
RewriteBase/

#remove php ext 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php 

#force trailing slash/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301] 

#other rewrites 
RewriteRule ^teachers/([^/\.]+)/$ /teachers/profile.php?u=$1 
RewriteRule ^teachers/([^/\.]+)/posts/$ /teachers/posts.php?u=$1 
RewriteRule ^teachers/([^/\.]+)/posts/([^/\.]+)/$ /teachers/post.php?u=$1&p=$2 

RewriteRule ^gallery/([^/\.]+)/$ /gallery/album.php?n=$1 
RewriteRule ^gallery/([^/\.]+)/slideshow/$ /gallery/slideshow.php?n=$1 
RewriteRule ^gallery/([^/\.]+)/([^/\.]+)/([^/\.]+)/$ /gallery/photo.php?a=$1&p=$2&e=$3 

편집 : 나는 정확히 내가 무슨 말의 스크린 샷을 첨부했다. enter image description here

+0

이'당신은'.htaccess' 파일을 추가하는 것을 잊었다 – Umbrella

+0

을 .htaccess' – jprofitt

+0

아차 .. 죄송합니다 .. 고정. –

답변

1

이 때문에 후행 슬래시 추가하는 당신의 결정이어야한다 : 당신이 쓰고 싶은 수도의 대신

#force trailing slash/ 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301] 

:

#force trailing slash/ 
RewriteCond %{REQUEST_FILENAME} !-f 
#the following rule only works for .php obviously, so add other rules 
RewriteCond %{REQUEST_URI} !\.php$ 
RewriteRule ^(.*)([^/])$ /$1$2/ [L,R=301] 

를 그리고, 당신은 301 리디렉션을 사용하기 때문에 브라우저가 리디렉션을 캐시 할 가능성이 높으므로 브라우저 캐시를 지워야 작동합니다.

+0

이것이 성공했습니다! 정말 고맙습니다! –

0

mod_rewrite 처리를 확실히하기 위해 .php 규칙의 끝에 [L]을 추가하십시오.

규칙과 일치하는 항목을 자주 찾으면 요청에 대해 실행하려는 유일한 규칙입니다. 마지막 6 개의 규칙은 이것의 예이기도합니다. 서로 겹치지 않기 때문에 당신이 그것없이 할 수 있다는 것을 제외하고는.

+0

모든'RewriteRule's? –

+0

특히 처음 두 개를 언급하고 있지만 나머지는 상호 독점으로 인해 선택 사항입니다. – Umbrella

+0

여전히 같은 결과를 얻고 있습니다 :/ –

0

다시 한번 살펴보면 다른 오류가 나타납니다. 분명히 조건을 공유하려고하는 두 가지 규칙이 있습니다. 이것은 작동하지 않습니다. 각 규칙은

#remove php ext 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/$ $1.php 
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php #this rule will always run 

그 이상

#remove php ext 
RewriteEngine on 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/$ $1.php 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/([^/]+)/$ $1/$2.php #this rule will always run 

로 변경해야 자신의 조건이 있어야하지만, 당신은 /로 끝나는 URL로 .php를 추가하려고? 당신은 잊었 아래

RewriteRule ^([^/]+)/$ $1.php 
관련 문제