2012-03-16 12 views
1

.htaccess 파일을 사용하여 .php없이 URL을 다시 쓰는 데 문제가 있습니다. 일부 주소에서는 작동하지만 다른 주소에서는 작동하지 않습니다. 여기 .. ​​내 htaccess로 파일에있는 것입니다 .htaccess를 사용하여 URL에서 .php를 제거 할 때 일부 URL이 작동하지 않습니다.

RewriteEngine On 

RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/$ $1.php 

#rewrite url up to 3 levels 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3.php 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_URI} !(\.[a-zA-Z0-9]{1,5}|/)$ 
RewriteRule (.*)$ /$1/ [R=301,L] 

나는 내 사이트의 다음 폴더/파일 구조를 ..을

index.php 
about-us 
    index.php 
    careers.php 
our-work 
    index.php 
    test.php 
    client1 
    example.php 

다음 URL이 작동 ..

example.com

example.com/about-us

example.com/our-work

example.com/our-work/client1/example

그러나이 작동하지 않습니다 ..

example.com/our-work/test

example.com/about-us/careers

방금 ​​404 오류가 발생합니다.

왜 이런 일이 발생하는지 알고 싶습니다.

답변

1

2 레벨 규칙은없고 1 레벨 및 3 레벨 규칙 만 있습니다. 당신은 추가해야합니다 :

#rewrite url to 2 levels 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/([^/]+)/$ /$1/$2.php 

당신은 아마도한다 RewriteCond 조건으로 3 수준의 규칙을 앞에해야

#rewrite url to 3 levels 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^([^/]+)/([^/]+)/([^/]+)/$ /$1/$2/$3.php 

이 규칙을 방지 할 수 불려 같은 이름 나있는 디렉토리가있는 경우 PHP 파일이 존재하지 않습니다.

+0

좋아요! 완벽하게 작동합니다 .. 감사합니다! – Dustin

관련 문제