2009-09-03 4 views
0

어떻게 new.example.comhtaccess의 일부 문제!

에 example.com/또는 www.example.com에서 내 사용자를 리디렉션 할 수 있지만 같은 일부 특정 URL을 리디렉션 할 해달라고 :

www.example.com/test.php 
api.example.com/testo.php 
www.example.com/forum/index.php 

내가 한 :

RewriteEngine on 
RewriteCond %{HTTP_HOST} ^example.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www.example.com$ 
RewriteRule ^(.*)$ http://new.example.com/$1 [R=301,L] 

그러나 URL에 대한 규칙은 무엇입니까?

답변

0

이렇게하는 한 가지 방법은 .htaccess 파일의 앞부분에서 (내부적으로 3XX 응답을 사용하지 않고) 내부로 리디렉션되는 특정 URL에 대한 추가 규칙을 먼저 만든 다음 L 플래그를 사용하여 나중에 규칙이 없도록하는 것입니다 해당 URL에 대해 처리됩니다. 예를 들어

:

RewriteEngine on 

# don't redirect these 
RewriteCond %{HTTP_HOST} ^www.example.com$ 
RewriteRule ^(/test.php)$ \1 [L] 

RewriteCond %{HTTP_HOST} ^api.example.com$ 
RewriteRule ^(/testo.php)$ \1 [L] 

RewriteCond %{HTTP_HOST} ^www.example.com$ 
RewriteRule ^(/forum/index.php)$ \1 [L] 

# redirect these 
RewriteCond %{HTTP_HOST} ^example.com$ [OR] 
RewriteCond %{HTTP_HOST} ^www.example.com$ 
RewriteRule ^(.*)$ http://new.example.com/$1 [R=301,L] 

나는 당신의 "리디렉션하지 않는다"요구 사항이 호스트 이름을 포함 있는지 확실하지 않습니다. 그렇지 않으면 RewriteCond 행을 제거하십시오.

+0

내가 어떻게 할 수 있습니까? –

+0

몇 가지 예제 코드를 추가했습니다. –