2014-10-18 3 views
0

내 웹 사이트 (http://panchr.me)에 대한 사용자 지정 다시 쓰기 구성표를 설정하려고합니다.htaccess - 인수에 대한 경로 다시 쓰기

은 여기 내 .htaccess :

RewriteEngine on 
ErrorDocument 404 /404.php 

RewriteCond %{REQUEST_URI} !-f 
RewriteCond %{REQUEST_URI} repositories 
RewriteRule ^(.+)repositories(.+) $1repositories?repo=$2 [nocase,last] 

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

은 특히, 내가 http://panchr.me/repositories?repo=some_namehttp://panchr.me/repositories/some_name과 같은 무언가를 다시 작성합니다. 그러나이 페이지를 방문하면 404 오류가 발생합니다. 또한 http://panchr.me/repositories을 방문하면 현재 500 오류가 발생합니다.

어떻게 해결할 수 있습니까? 다음과 같이

내 서버 구조는 다음과 같습니다

.htaccess 
# a few other files, not available to user 
public_html/ # this is the DocumentRoot 
    index.php 
    repositories.php 
    # more files 

답변

2

귀하의 조건과 규칙이 아무 의미도하지 않습니다이 작동합니다 :

RewriteEngine On 
RewriteBase/
ErrorDocument 404 /404.php 

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(repositories)(\.php)?/([^/]+)$ $1.php?repo=$3 [NC,L] 
# alternatively to the above RerwriteRule you could try 
# (comment the above RewriteRule if u do and leave the conditions uncommented) 
#RewriteRule ^(repositories)(?:\.php|)/([^/]+)$ $1.php?repo=$3 [NC,L] 

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

파일이나 폴더에 존재하지 않는 경우는 거의 말한다 2 조건 :

RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 

그런 다음 RewriteRule에는 anyt 힝 즉, 예를 들어, repositories/anything입니다 :

http://panchr.me/repositories/moduleA 
http://panchr.me/repositories/other 
http://panchr.me/repositories/some_name 
+0

그것이 (선택적으로) 일치'repositories.php/some_name'에도 수 있습니까? 나는 RewriteRule을'RewriteRule^([^ \.] +) (리포지토리) (?: \ php)로 보았습니다.?/([^ /] +) $ $ 1 $ 2.php? repo = $ 3 [NC, L]' , 그러나 이것은 인수로 제공하지 않습니다. (다른 규칙을 어지럽히 지 않고 RewriteBase를 설정할 수 없기 때문에 처음에는'([^ \.] +)'를 사용해야했습니다). –

+0

@RushyPanchal 그래서'저장소가 정확히 어디에 있습니까? 아마도 당신이 당신의 구조에 대해 더 많이 말하면 나는 당신에게 더 나은 대답을 줄 수 있습니다. '([^ \.] +)'는 점이 아닌 어떤 것과도 일치합니다. '저장소'앞에 올 것 같습니까? ** 존재하는 경우 폴더를 각각의'php '로 리디렉션하는 맨 아래 규칙 인'RewriteBase'를 사용하는 다른 규칙이 있습니까 ** – Prix

+0

원래 질문을 서버 구조로 업데이트했습니다. 본질적으로'.htaccess'는'repositories.php'의 _parent 디렉토리에 있습니다. 당신의 대답에 덧붙여'(? : \. php)?'는'.php'의 선택적 매치가되어야합니다. 재 작성을하면 다음과 같이 할 수 있습니다 : 'panchr.me/repositories/test' ->'panchr.me/repositories.php? repo = test' (이미 작동 중) 'panchr.me/repositories. php/test' ->'panchr.me/repositories.php? repo = test' (이것은 작동하지 않습니다). –