Interstage HTTP Server 運用ガイド
|
目次
索引

|
3.2.12 リライト機能の設定
リライト機能は、環境定義ファイル(httpd.conf)において、URLを書き換える条件および書き換えのルールを正規表現で設定し、その書き換え条件やルールを満たしている場合にURLを書き換えます。
リライト機能の設定例を以下に示します。

- バーチャルホストでは、バーチャルホストごとにリライト機能のディレクティブを設定してください。
- ServletサービスのアプリケーションのURLに対してリライト機能を設定する場合は、<Location>セクションの中に、リライト機能のディレクティブを設定してください。
- 書き換えたURLがServletサービスのアプリケーションのURLである場合、外部リダイレクトの指定だけが有効となります。

クライアントのIPアドレスが“192.168.0.”で始まる場合、URLを“/ext”に内部リダイレクトする

LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.
RewriteRule ^/(.*)$ /ext/$1 |

LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{REMOTE_ADDR} ^192\.168\.0\.
RewriteRule ^/(.*)$ /ext/$1 |

Webブラウザ(クライアント)から先頭文字列が“/somepath”ではないURLが指定された場合、URLを“otherhost”に外部リダイレクトする

LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/somepath
RewriteRule ^/(.*)$ http://otherhost/$1 |

LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{REQUEST_URI} !^/somepath
RewriteRule ^/(.*)$ http://otherhost/$1 |

HEADメソッドまたはOPTIONSメソッドのリクエストを受け付けた場合、ステータスコード“403”(Forbidden)で応答する

LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(HEAD|OPTIONS)$
RewriteRule .* - [F] |

LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{REQUEST_METHOD} ^(HEAD|OPTIONS)$
RewriteRule .* - [F] |

アクセスされたWebブラウザの種類により、異なるページを表示する
− Internet Explorerの場合:ファイル名に“-i”を付加したhtmlページ
− Internet Explorer以外の場合:ファイル名に“-o”を付加したhtmlページ

LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteRule ^/(.*)\.html /$1-i.html [L]
RewriteRule ^/(.*)\.html /$1-o.html [L] |

LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
RewriteEngine On
RewriteCond %{HTTP_USER_AGENT} .*MSIE.*
RewriteRule ^/(.*)\.html /$1-i.html [L]
RewriteRule ^/(.*)\.html /$1-o.html [L] |

Webブラウザ(クライアント)からServletサービスのアプリケーション識別子“sample1”のURLが指定された場合、URLを“sample2”に外部リダイレクトする
注)RewriteRuleディレクティブで評価されるURLは、<Location>セクションで指定したURL“/sample1/”を除いた部分になります。

LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
<Location /sample1/>
RewriteEngine On
RewriteRule ^(.*)$ /sample2/$1 [R]
</Location> |

LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
<Location /sample1/>
RewriteEngine On
RewriteRule ^(.*)$ /sample2/$1 [R]
</Location> |

Webブラウザ(クライアント)から先頭文字列が“/info/”のURLが指定された場合、プロキシ要求とみなし、“originhost”にリクエストを転送する
注)URLが“/info”の場合は、URLを“/info/”に書き換えた後、プロキシ動作を実行します。
“https”は、転送するリクエストに指定できません。

LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
LoadModule proxy_module "C:/Interstage/F3FMihs/modules/mod_proxy.so"
LoadModule proxy_connect_module "C:/Interstage/F3FMihs/modules/mod_proxy_connect.so"
LoadModule proxy_http_module "C:/Interstage/F3FMihs/modules/mod_proxy_http.so"
RewriteEngine On
RewriteRule ^/info$ /info/
RewriteRule ^/info/(.*)$ http://originhost/info/$1 [P] |

LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
LoadModule proxy_module "/opt/FJSVihs/modules/mod_proxy.so"
LoadModule proxy_connect_module "/opt/FJSVihs/modules/mod_proxy_connect.so"
LoadModule proxy_http_module "/opt/FJSVihs/modules/mod_proxy_http.so"
RewriteEngine On
RewriteRule ^/info$ /info/
RewriteRule ^/info/(.*)$ http://originhost/info/$1 [P] |

Webブラウザ(クライアント)からファイル名の拡張子“cgi”のURLが指定された場合、/cgi-bin配下のCGIを実行する

LoadModule cgi_module "C:/Interstage/F3FMihs/modules/mod_cgi.so"
LoadModule rewrite_module "C:/Interstage/F3FMihs/modules/mod_rewrite.so"
ScriptAlias /cgi-bin/ "C:/Interstage/F3FMihs/servers/FJapache/cgi-bin/"
RewriteEngine On
RewriteRule ^/(.+\.cgi)$ /cgi-bin/$1 [PT] |

LoadModule cgi_module "/opt/FJSVihs/modules/mod_cgi.so"
LoadModule rewrite_module "/opt/FJSVihs/modules/mod_rewrite.so"
ScriptAlias /cgi-bin/ "/opt/FJSVihs/servers/FJapache/cgi-bin/"
RewriteEngine On
RewriteRule ^/(.+\.cgi)$ /cgi-bin/$1 [PT] |
関連ディレクティブ
Copyright 2008 FUJITSU LIMITED