Interstage HTTP Server 運用ガイド
目次 索引 前ページ次ページ

付録A ディレクティブ一覧

A.80 RewriteRule

名前

 RewriteRule

形式

 RewriteRule URLパターン 置換文字列 [フラグ]

機能概要

 URLを書き換えるためのルールを設定します。
 RewtiteCondディレクティブなどのリライト関連のディレクティブと組み合わせて、柔軟にURLを書き換えることができます。

 URLパターン
 書き換えの対象となるURLを正規表現で指定します。
 置換文字列
 URLパターンにマッチした場合に、書き換えるURLを指定します。
 以下の変数を指定することもできます。
 フラグ(省略可)
 フラグを、角括弧([])で囲んで指定します。複数のフラグを指定する場合は、角括弧([])内にカンマ(,)で区切って指定してください。
 指定可能なフラグを以下に示します。

指定位置

 グローバルコンテキスト、バーチャルホスト、ディレクトリ

省略値

 なし

モジュール

 mod_rewrite

注意事項

使用例

 クライアント(Webブラウザ)からリクエストを受信した場合に、本ディレクティブに設定した各ルールに従って書き換えられたURLを以下の表に示します。

設定内容

クライアントからのリクエスト

置換後のURL(注)

RewriteRule ^/somepath(.*) /otherpath$1

GET /somepath/pathinfo

/otherpath/pathinfo
(内部リダイレクト)

RewriteRule ^/somepath(.*) /otherpath$1 [R]

GET /somepath/pathinfo

http://thishost/otherpath/pathinfo
(外部リダイレクト)

RewriteRule ^/somepath(.*) http://thishost/otherpath$1

GET /somepath/pathinfo

/otherpath/pathinfo
(内部リダイレクト)

RewriteRule ^/somepath(.*) http://thishost/otherpath$1 [R]

GET /somepath/pathinfo

http://thishost/otherpath/pathinfo
(外部リダイレクト)

RewriteRule ^/somepath(.*) http://otherhost/otherpath$1

GET /somepath/pathinfo

http://otherhost/otherpath/pathinfo
(外部リダイレクト)

RewriteRule ^/somepath(.*) http://originhost/otherpath$1 [P]

GET /somepath/pathinfo

http://originhost/otherpath/pathinfo
(リバースプロキシ)

RewriteRule ^/(.+\.cgi)$ /cgi-bin/$1 [PT]

GET /test.cgi?abc

/cgi-bin/test.cgi?abc

RewriteRule ^/(.+\.cgi)$ /cgi-bin/$1 [PT,QSA]

GET /test.cgi?abc

/cgi-bin/test.cgi?abc

RewriteRule ^/(.+\.cgi)$ /cgi-bin/$1?xyz [PT]

GET /test.cgi?abc

/cgi-bin/test.cgi?xyz

RewriteRule ^/(.+\.cgi)$ /cgi-bin/$1?xyz [PT,QSA]

GET /test.cgi?abc

/cgi-bin/test.cgi?xyz&abc

注)各ホスト名は、以下を意味します。


目次 索引 前ページ次ページ

Copyright 2007 FUJITSU LIMITED