2013-11-02 2 views
0

example.com에서 jp.example.com까지 "home /""car /"으로 시작하는 모든 URL과 유일한 URL을 리디렉션 할 수있는 방법이 필요합니다. 그래서 예를 들면이 경우에만 다시 쓰는 방법은 무엇입니까?

:

RewriteEngine on 
RewriteCond %{HTTP_HOST} !^jp.example.com$ 
RewriteRule ^(.*)$ http://jp.example.com/$1 [R=301] 

하지만 jp.example.com

에 example.com의 모든 URL을 다시 있기 때문에 작동하지 않습니다이 코드를 사용하고

example.com/home/test.html ---> jp.example.com/home/test.html 
example.com/car/test.html ---> jp.example.com/car/test.html 
jp.example.com/home/second-test.html ---> jp.example.com/home/second-test.html 
jp.example.com/third-test.html ---> example.com/third-test.html 

답변

0

요청한 URI가 /home 또는 /car으로 시작하는지 확인해야합니다 (예 :

).
RewriteEngine on 
RewriteCond %{HTTP_HOST} !^jp.example.com$ [NC] 
RewriteCond %{REQUEST_URI} ^(/home|/car)(/.*)?$ [NC] 
RewriteRule ^(.*)$ http://jp.example.com/$1 [R=301] 
이러한 규칙을 사용할 수 있습니다
0

:

RewriteEngine on 

# conditions 1 & 2 
RewriteCond %{HTTP_HOST} ^(www\.)?(example\.com)$ [NC] 
RewriteRule ^(home|care)/ http://jp.%1%{REQUEST_URI} [L,NC,NE,R=301] 

# conditions 3 
RewriteCond %{HTTP_HOST} ^jp\.example\.com$ [NC] 
RewriteRule ^(home)/second_(test\.html)$ /$1/$2 [L,NC,R=301] 

# conditions 4 
RewriteCond %{HTTP_HOST} ^jp\.(example\.com)$ [NC] 
RewriteRule ^(third-test\.html)$ http://%1/$1 [L,NC,R=301] 
관련 문제