2011-02-27 3 views
0

이전 서버를 archive.example.com으로 옮길 예정이며 모든 www URL이 example.com 또는 archive.example.com으로 정규화되어 있지만 새 서버는 example.com에서 계속 실행되며 후행 슬래시 문제.RewriteRule : 이전 경로를 보관 서버로 리디렉션하고 www가 아닌 ​​도메인으로 정규화 하시겠습니까?

이전 서버에는 많은 디렉토리가 있으므로 새 서버에서 실행될 몇 개의 디렉토리를 제외하고 모든 것이 경로 정보를 유지하면서 archive.example.com으로 리디렉션해야합니다. 내가 리디렉션 할하지 않고 새로운 서버에 남아있을 것입니다 디렉토리는 다음과 같습니다 예를 들어

 
/(root) 
/static 
/blog 
/about 

:

 
example.com => example.com 
www.example.com => example.com 
www.example.com/ => example.com/ 

example.com/blog => example.com/blog 
www.example.com/blog => example.com/blog 
www.example.com/blog/ => example.com/blog/ 

다른 모든 디렉토리가 archive.example.com로 리디렉션합니다. 예를 들어 :


ServerName example.com 
ServerAlias www.example.com 
UseCanonicalName On 

# canonicalize www.example.com to example.com 
RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] 
RewriteRule ^(.*)$ $1 [R=301] 

# redirect everything to archive.example.com except for a few directories 
RewriteCond %{REQUEST_URI} !^(/|/static|/blog|/about)$ 
RewriteRule ^/(.*)$ http://archive.example.com/$1 [NC,R=301,L] 

이 정확 및/또는 더 정확한 방법이 :

여기
 
example.com/docs => archive.example.com/docs 
www.example.com/docs => archive.example.com/docs 
www.example.com/docs/ => archive.example.com/docs/ 

example.com/library/images => archive.example.com/library/images 
www.example.com/library/images => archive.example.com/library/images 
www.example.com/library/images/ => archive.example.com/library/images/ 

내가 내 httpd.conf 파일에있는 무엇인가?

답변

0

저는 이전 사이트로 리디렉션 된 RewriteRule을 사용하여 문제를 발견했다고 생각합니다.

 

# redirect everything to archive.example.com except for a few directories 
RewriteCond %{REQUEST_URI} !^(/|/static|/blog|/about)$ 
RewriteRule ^/(.*)$ http://archive.example.com/$1 [NC,R=301,L] 
 

... 내가이 재 작성 :

 

# redirect everything to archive.example.com except for a few directories 
RewriteCond %{REQUEST_URI} !^/$ 
RewriteCond %{REQUEST_URI} !^/static.*$ 
RewriteCond %{REQUEST_URI} !^/blog.*$ 
RewriteCond %{REQUEST_URI} !^/about.*$ 
RewriteRule ^(.*)$ http://archive.example.com%{REQUEST_URI} [NC,R=301,L] 
 

여기 왜

이 내가 질문을 게시 할 때 내가 가진 것입니다.

첫 번째로 볼 수 있듯이 새로운 사이트가 커짐에 따라 제외 디렉토리를 추가 할 수 있기 때문에 하나의 다시 쓰기 조건을 4 가지 조건으로 나누었습니다.

또한/static,/blog/및/about 다음에 점 별표를 추가하여 최상위 수준이 아닌 해당 디렉토리의 모든 경로와 일치하게됩니다.

마지막으로 RewriteRule 행에서 패턴에서 선행 슬래시를 제거하고 후행/$ 1을 % {REQUEST_URI}로 변경했습니다. 패턴에서 변수를 저장할 필요가 없습니다. 단지 서버 이름을 변경해야합니다. 패턴에서 경로를 추출하는 대신 동일한 % {REQUEST_URI} 변수를 사용하여 패턴을 추출했습니다. 이전 4 줄에 사용되었습니다.

BTW : 크롬이 DNS/경로 정보를 캐싱하기 때문에 처음에는 나를 혼란스럽게 만들었습니다. Ctrl-F5를 누르면 캐시가 삭제되어 변경 사항을 볼 수 있습니다.

0
RewriteEngine On 
RewriteCond %{HTTP_HOST} !^gotactics.net$ [NC] 
RewriteRule ^(.*)$ http://gotactics.net/$1 [L,R=301] 

이렇게하면 www. 당신이 그것도 변경할 수 있는지 확인하십시오.

관련 문제