RedirectPermanent 및 RewriteRule

RedirectPermanent 및 RewriteRule

현재 다음 형식의 줄이 있는 Apache 구성 스택에 포함되는 perm_redirects.conf 파일이 있습니다.

RedirectPermanent /old/url/path /new/url/path

새 경로에 절대 URL(예: )을 사용해야 하는 것 같습니다 http://example.com/new/url/path. 내가받는 로그에서"불완전한 리디렉션 대상 /new/url/path가 다음으로 수정되었습니다.http://example.com/new/url/path."(의역).

에 대한 2.2 문서에서 RewriteRule하단에는 리디렉션의 오른쪽에 대한 절대 URL 대신 URL 경로만 사용하여 유효한 리디렉션으로 다음이 표시됩니다.

RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]

하지만 해당 버전의 기능을 복제하기 위해 해당 형식을 사용할 수는 없는 것 같습니다 RedirectPermanent. 이것이 가능한가?

답변1

WFM:

RewriteEngine On
RewriteOptions Inherit 
RewriteRule ^/old/url/path(.*) /new/url/path$1 [R]

결과:

wget http://localhost/old/url/path/foo
--2010-08-09 15:41:20--  http://localhost/old/url/path/foo
Resolving localhost... 127.0.0.1
Connecting to localhost|127.0.0.1|:80... connected.
HTTP request sent, awaiting response... 302 Found
Location: http://localhost/new/url/path/foo [following]
--2010-08-09 15:41:20--  http://localhost/new/url/path/foo

참고 (1) 아마도 [R=permanent]를 원할 것입니다. 기본값은 임시 리디렉션입니다. (2) [L]만 사용하면 최종 사용자가 볼 수 없는 내부 리디렉션이 발생하므로 원하지 않습니다(L로 인한 것이 아니라 기본 동작 ""이 내부 리디렉션임). RedirectPermanent는 최종 사용자에게 3xx 응답을 생성합니다. L, 즉 [R=permanent,L]을 추가하여 mod_rewrite가 더 이상 규칙을 처리하지 못하도록 할 수 있습니다.

관련 정보