2012-11-25 5 views
0

그래서 이상한 문제가 있습니다. 나는htaccess에서 다시 쓰기 문제

mysite.com/brand/example/ex1 

mysite.com/brand.php?brand=example&ref=ex1 

에서 재 작성 규칙을 가지고 그리고 난 그렇게 관리하지만 또 다른 문제도있다 : 당신은이를 입력 할 때 :

mysite.com/brand/example/ex1.html 

또는

mysite.com/brand/example/ex1.php 

알겠습니다.

mysite.com/brand/example/ex1?ref=ex1.php&brand=example 

왜이 리디렉션을 가져오고 제거하는 방법을 알 수 있습니까?

RedirectMatch ^brand/([A-Za-z0-9-\.\_]+)/([A-Za-z0-9-\.\_]+)php$ /brand/$1/$2 

나이 :

나는이 시도

RedirectMatch ^brand/([A-Za-z0-9-\.\_]+)/([A-Za-z0-9-\.\_]+)\.php$ /brand/$1/$2 

을하지만, 단순히 작동하지 않습니다.

제발 도와주세요!

답변

0

나는 이것에 대한 mod_rewrite을 사용 : 모두 RewriteCond이 유효한 경우

RewriteEngine On 
RewriteCond %{REQUEST_URI} =/brand.php 
RewriteCond %{QUERY_STRING} ^brand=([^&]+&ref=(.+)$ 
RewriteRule .* /brand/%1/%2? [L,R] 

RewriteRule 만 적용됩니다. 첫 번째 RewriteCond은 요청 URL을 /brand.php으로 비교하고 두 번째는 정규 표현식을 쿼리 문자열과 비교하여 일치 항목을 %1%2에 각각 저장합니다.

RewriteRule에는 쿼리 문자열에서 일치하는 부분을 사용하여 다시 쓰여진 URL입니다.

+0

이 코드의 기능을 알려주십시오. –

+0

@AlickDikan 님이 답변을 업데이트했습니다. –