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下部には、リダイレクトの右側に abs URL ではなく url-paths のみを使用した、有効なリダイレクトとして次の内容が示されています。

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

しかし、そのフォーマットではバージョンの機能を再現できないようですRedirectPermanent。これは可能ですか?

答え1

週:

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 がそれ以上のルールを処理しないようにすることができます。

関連情報