2016-12-22 3 views
0

나는 html/php 응용 프로그램에서 로컬 서버에서 일하고 있어요 내가 성공htaccess로 URL 재 작성은 작동하고 있지만 재

응용 프로그램이 ./Compta/index.php에 저장하지 않고 아파치 URL 재 작성 모듈을 사용하려고 해요. http://localhost/Compta/Test/

대신 : 나는 ./Compta/.htaccess

난 단지처럼 재 작성된 URL을 사용하고 싶습니다에 .htaccess 파일을 가지고 그들이 이전 URL로 이동하려고하면 http://localhost/Compta/index.php?page=test

및 사용자를 리디렉션

htaccess로 파일에는 다음이 포함

Options +FollowSymlinks 

RewriteEngine on 

RewriteRule ^([[:alnum:]]*)/$ /Compta/index.php?page=$1 [L] 

RewriteRule ^([[:alnum:]]*)$ /Compta/index.php?page=$1 [L] 

RewriteCond %{REQUEST_URI} ^/index\.php$ 
RewriteCond %{QUERY_STRING} ^page=([[:alnum:]]*)$ 
RewriteRule ^(.*)$ http://localhost/Compta/%1/ [L,R=301] 

나는 t을 갈 때 오 http://localhost/Compta/Test/ 다음 줄이 작동하고 내 코드는 사업부에 test.php의 내용이 포함

나는 다음 줄이 작동 http://localhost/Compta/Test로 이동하지만, 파이어 폭스에서 URL이 http://localhost/Compta/index.php?page=Test에 다시 작성하고 이런 일이되지
RewriteRule ^([[:alnum:]]*)/$ /Compta/index.php?page=$1 [L] 

http://localhost/Compta/Test2; url은 다시 작성되지 않습니다.

RewriteRule ^([[:alnum:]]*)$ /Compta/index.php?page=$1 [L] 

이 문제를 해결하기 위해 내가이 라인을 추가 이전 URL 리디렉션 :

RewriteCond %{REQUEST_URI} ^/index\.php$ 
RewriteCond %{QUERY_STRING} ^page=([[:alnum:]]*)$ 
RewriteRule ^(.*)$ http://localhost/Compta/%1/ [L,R=301] 

하지만이 작동하지 않습니다 내가 http://localhost/Compta/index.php?page=Test에 갈 때 URL이 http://localhost/Compta/Test/

에 다시 작성되지 않습니다

미리 감사드립니다.

답변

0

.htaccess로 해결 방법을 찾지 못했습니다.하지만 PHP로 발견하여 PHP 파일 상단에 다음 줄을 추가했습니다. :

 if(preg_match("/\/Compta\/index\.php\?page=([[:alnum:]]*)/",@$_SERVER['REQUEST_URI'],$page)&&!empty($page[1])) 
     { 
      $new_url = "/Compta/"; 
      switch (strtolower($page[1])) { 
       case "test": 
        $new_url = $new_url."Test/"; 
        break; 
       case "test2": 
        $new_url = $new_url."Test2/"; 
        break; 
       default:break; 
      } 
      header("Status: 301 Moved Permanently", false, 301); 
      header("Location: ".$new_url); 
      exit; 
     } 

URL이 "/Compta/index.php?page="로 시작하면 내가 테스트하고 매개 변수 "페이지"에 대한이있는 경우 가 그럼 난 새 URL이 스위치 포함 된 변수를 초기화 내 매개 변수의 내용 새 URL 을 수정 한 다음 새 URL로 리디렉션합니다.