2013-01-23 4 views
0

http://example.com/index.php?path=controller/functionhttp://example.com/controller/function으로 마스킹하고 싶습니다. function이 반드시 필요하지는 않습니다.URL 경로를 매개 변수로 다시 변환

htaccess 파일로 어떻게 할 수 있습니까?

다음은 작동하지 않습니다. 내가 브라우저에서 http://example.com/controller/function을 입력하면

RewriteRule ^/?assets/(.*)$ assets/$1 [L] # directory for CSS, images, and JavaScript 
RewriteRule ^$ /index [redirect] 
RewriteRule ^([a-zA-Z]+)/?([a-zA-Z/]*)$ index.php?path=$1/$2 [L] 

현재, 나는 404 오류,하지만 http://example.com/index.php?path=controller/function 작품 입력을받을 수 있습니다.

감사합니다.

답변

4

이 작업을 시도 할 수 있습니다 :

http://example.com/index.php?path=var1/var2

들어오는 후행 슬래시 행동과을 유지 :

RewriteEngine On 
RewriteBase/
RewriteCond %{REQUEST_URI} !index\.php [NC] 
RewriteRule ^([^/]+)(.*)?$ index.php?path=$1$2 [L] 

이 내부적으로

http://example.com/var1/var2

매핑 0은 선택 사항입니다.

+0

효과가 있습니다. 고맙습니다. –

+0

'http : // example.com/uploads/var1/var2/file.txt'를'http : //example.com/index.php? filepath = var1/var2/file.txt'로 다시 작성해야한다면 어떻게해야합니까? ? –

관련 문제