단일 RewriteRule
을 사용하는 것은 실제로 매우 간단합니다. 단, RewriteCond
을 추가하여 도메인을 기반으로 리디렉션을 제한 할 수도 있습니다.
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{HTTP_HOST} (www\.)?example\.com
RewriteRule ^$ http://example.com/all/ [QSA,R=301]
이 리디렉션을 할 것이며, 리디렉션 된 URL의 끝에 쿼리 문자열을 추가해야합니다 : 그러나
http://www.example.com/?brand=123&color=red
=> http://example.com/all/?brand=123&color=red
http://example.com/?brand=123&color=red&size=colin
=> http://example.com/all/?brand=123&color=red&size=colin
하는 것으로 우리는 빈 경로합니다 (의 ^$
일치하고로 당신은 또한 요청하는 경우 재 지정하려면
http://example.com/all/?brand=123 : not redirected
http://example.com/index.php?brand=123 : not redirected
: 그것은 그 문제에 대한 모든 /all
이미 요청 ... 또는 다른 어떤 리디렉션되지 않습니다) 지배 물론
RewriteCond %{QUERY_STRING} !^$
RewriteCond %{HTTP_HOST} (www\.)?example\.com
RewriteRule ^(index.php)?$ http://example.com/all/ [QSA,R=301]
, 당신은 당신의 자신의 도메인 이름 곳으로 'example.com'을 교체해야합니다 : 에드 URL은 다음 (I 예로 들어 index.php를 사용할 것이다), 당신이 할 것 인덱스 파일입니다 너는 그것을 본다.
편집는 : 나는 쿼리 문자열이 URL에 전달되는 경우 재 작성에만 발생하는 것을 의미합니다 추가 RewriteCond
을 추가했습니다.
: (. www가 \)한다 RewriteCond % {HTTP_HOST}을 사이트 \ .COM RewriteRule의?^$ http://www.site.com/all-products [QSA, R = 301] 그리고 site.allallproducts로 리다이렉트하면 홈페이지로 갈 수 없었습니다. –
Ah ('? brand = 123 ...'부분) 만 있다면 재 작성을 원하십니까? 내 대답을 업데이트했습니다. – icabod
완벽하게 작동합니다. 감사합니다 –