2013-04-17 2 views
0

작동하지 않는 htaccess 파일이있는 프로젝트에서 내 수업을 진행하고 있습니다. 나는이있다 :htaccess의 규칙 충돌

내가 /section/function/ 같은 URL을 조회 할 경우에, 나는 /myroot/index.php?type=section &을 얻어야한다 : 사실

SetEnvIf Request_URI^root=/myroot/ 

RewriteRule ^(assets|inc) - [L] 
RewriteRule ^section[/]?$ %{ENV:root}section/index  
RewriteRule ^section/function/(.*)$ %{ENV:root}index.php?type=section&action=function [L] 
RewriteCond %{QUERY_STRING} ^(.*)?$ 
RewriteRule ^section/(.*)$      %{ENV:root}index.php?type=section&action=view [L] 
RewriteRule ^index\.php$ - [L] 

를, 내가 이해하지 못하는 세 가지가있다 조치 = 기능을했지만 내 브라우저에서 localhost/section/function이 발생하여 오류가 발생합니다. url은 양방향으로 변환됩니까? myroot/index.php? type = section & action = 브라우저에 /section/function/으로 나타나는 함수입니다. 마지막 줄을 지우면 빈 오류 페이지가 나타납니다. 왜 그렇습니까?

편집 : 그래서 컨 포멀 올라프 DIETSCHE는 말에

, 내가

한다 SetEnvIf REQUEST_URI^루트 =/myroot/

RewriteRule ^(assets|inc) - [L] 
RewriteRule ^section[/]?$ %{ENV:root}section/index  
RewriteRule ^section/function/(.*)$ %{ENV:root}?type=section&action=function [L] 
RewriteCond %{QUERY_STRING} ^(.*)?$ 
RewriteRule ^section/(.*)$      %{ENV:root}?type=section&action=view [L] 
RewriteRule ^index\.php$ - [L] 

에 규칙을 변경하지만 <a href="section/somefunction"></a>에 클릭하면, I 페이지 localhost/section/some function을 보여줍니다. 난 정말 당신이 규칙이 작동하려면에 대한 htaccess로에

RewriteEngine on 

이 있어야

답변

0

먼저 .... 잘못 무슨 일이 일어나고 있는지 모른다.

규칙 요청을 다시 작성하지만 은 클라이언트을 리디렉션하지 않습니다. 둘 사이의 차이는 클라이언트를 말하지 않고, 클라이언트에 다른 페이지의 내용을 보내

  • 입니다. 클라이언트는 요청한 페이지의 내용을 가지고 있다고 생각합니다.
  • 다른 URL을 클라이언트로 보내면 클라이언트는이 URL로 새로운 요청을하게됩니다. 클라이언트는 다른 페이지의 내용을 수신했다는 것을 알고 브라우저 바에 표시합니다. 때문에,

    당신은 대체 앞에 %{ENV:root}을 제거해야합니다 : 클라이언트를 재 지정하려면

, 당신은 RewriteRule

RewriteRule ^section/function/(.*)$ %{ENV:root}index.php?type=section&action=function [R,L] 

업데이트R 플래그를 추가해야합니다 예 : URL입니다. /index.php 아니요 /myroot/index.php

RewriteRule ^section[/]?$ /section/index  
RewriteRule ^section/function/(.*)$ /index.php?type=section&action=function [L] 
RewriteCond %{QUERY_STRING} ^(.*)?$ 
RewriteRule ^section/(.*)$ /index.php?type=section&action=view [L] 
RewriteRule ^index\.php$ - [L] 
+0

설명해 주셔서 감사합니다. 물론 RewriteEngine을 켜기로 설정 했는데도 여전히 작동하지 않습니다. 왜 그렇습니까? – user1611830

+0

@ user1611830 필자는 테스트 환경에서 규칙을 시험해 보았고, *'/ section/function'을'/ myroot/index.php'로 다시 작성했습니다. error.log 메시지가 없으면 알기가 어렵습니다. 예를 들어'/ myroot /'가 서브 디렉토리가 아닌 * 문서 루트 * 인 경우,'index.php'에 그 파일을 첨가해서는 안됩니다. 그것이 하위 디렉토리라면'index.php'가 없을 수도 있습니다. PHP 스크립트 자체에 오류가있을 수 있습니다. –

+0

죄송합니다. 귀찮게하지 않으려 고합니다. 하지만 실제로/myroot는 루트 폴더이므로 규칙을 업데이트 (규칙 참조)하지만 아무 것도 변경하지 않았습니다. – user1611830