|
mod_rewrite.c ファイルに含まれます。
これは、リクエストされた URL をルールに基づいて書き換えるエンジンの
機能を提供します。
mod_rewrite はデフォルトではコンパイルされません。
mod_rewrite を使用する為にはコンフィグレーションファイルを
次の行のように構築しなければなりません:
AddModule modules/standard/mod_rewrite.o
これは、不正確な一致による無制限な追加のルール条件(HTTP のヘッダーを含むたくさんの変数を操作するため)と、先にある URL の代用による外部のデータベース検索(あるいはプレインテキストテーブル、DBM ハッシュファイルや、外部の処理によって)をサポートします。
次の両方を含む、フルの URL(PATH_INFOパートを含む)を操作します。 per-server文(httpd.conf)とper-dir文(.htaccess) とさらに結果のQUERY_STRINGの一部を生成することができます。 書き換えられた結果は、内部のサブプロセスで読み込むことが出来、外部のリクエストをリダイレクト(変換)するか、内部のProxyを通すことも可能です。
このモジュールは 1996 年の 4 月に独自に書かれたもので、1997 年の 7 月には Apache グループのものとなっています。
Ralf S. Engelschall
rse@engelschall.com
www.engelschall.com
RewriteEngine {on,off}RewriteEngine off
RewriteEngine 命令はランタイム書き換えエンジンを有効又は無効にします。
off を設定すると、このモジュールはランタイム処理を行いません。環境変数SCRIPT_URxの更新もしません。
全ての RewriteRule 命令を無効にする為に、この命令を使ってください!
デフォルトでは rewrite コンフィギュレーションは受け継がれていません。これは RewriteOptions inherit が可能にならない限り、それぞれのバーチャルホストで RewriteEngine on 命令を持つ必要があることを意味します。
RewriteOptions
Syntax: RewriteOptions Option ...
Default: -None-
Context: server config, virtual host, per-directory config
RewriteOption 命令は、いくつかの特殊オプションである、現在のper-server またはper-directory コンフィグレーションを設定します。 Option文字列は次のようにできます:
inherit'
RewriteLog
Syntax: RewriteLog Filename
Default: -None-
Context: server config, virtual host
RewriteLog 命令はサーバで書き換えたアクションを格納するファイル名を設定します。 ファイル名がスラッシュ('/') で始まらない時は、Server Rootからの相対パスとなります。 この命令はサーバの設定につき1つだけ行えます。
書き換え操作のログを行わないようにする際は、 Filenameを
/dev/nullにする必要がありません。なぜなら書き換えエンジンは
内部的にログを出力していますが、ログファイルを生成しません。
これはサーバをスローダウンさせ、管理者になにも利益がありません!
ロギングを無効にするにはRewriteLog 命令をを削除するかコメントアウト
するか、RewriteLogLevel 0を使用してください!
|
| SECURITY: See the Apache Security Tips document for details on why your security could be compromised if the directory where logfiles are stored is writable by anyone other than the user that starts the server. |
Example:
RewriteLog "/usr/local/var/apache/logs/rewrite.log"
RewriteLogLevel
Syntax: RewriteLogLevel Level
Default: RewriteLogLevel 0
Context: server config, virtual host
RewriteLogLevel 命令は書き換えログの冗長性のレベルを設定します。 デフォルトレベルの 0 は何もロギングしません。9 までまたはそれ以上は、 さらに多くのログ情報が書き出されます。
ログ出力を無効にするには、Level を 0 に設定してください。 これは全ての処理のログを無効にします。
| 注意: 高いLevel を使用すると劇的にApacheサーバは遅くなります! 書き換えログファイルはデバッグの時に使用し、少なくとも 2 以下のを使ってください! |
Example:
RewriteLogLevel 3
RewriteMap
Syntax: RewriteMap Mapname {txt,dbm,prg}:Filename
Default: not used per default
Context: server config, virtual host
RewriteMap命令はキー検索を通してフィールドを挿入/代用するためにマッピング機能によってルール代理ストリングの中で使える外部のRewriting Mapを定義します。
Mapnameはマップの名前であって、書き換えルールの代理ストリングスのためにマッピング機能を指定するために使われます。
このような命令がある時 マップMapnameは調べられ、キーLookupKeyは検索されます。もしキーが見つかれば、マップ機能命令はSubstValueによって代わりに割り当てられます。もしキーが見つからなければ、それはDefaultValueによって割り当てられます。${Mapname:LookupKey|DefaultValue}
Filenameは次のフォーマットの一つを含んでいる有効な Unix ファイルパスです:
これはいずれかのブランク行、コメント行('#' で始まっている)を含んでいるアスキーファイルであるか、または
MatchingKey SubstValue対ー行ごとに一つ。適当なエディタを使うか、またはmod_rewriteが分配するsupportディレクトリからmapcollect、mapmergeというプログラムを使って、手動でこのようなファイルを作ることができます。
txt:と一緒にマップの接頭部をFilenameとして示すこと:以下の例のようなストリング:
# # map.real-to-user -- maps realnames to usernames # Ralf.S.Engelschall rse # Bastard Operator From Hell Dr.Fred.Klabuster fred # Mr. DAU |
RewriteMap real-to-host txt:/path/to/file/map.real-to-user |
NDBM フォーマットファイルが同じ中身を持っていることを示します。Apache のsupportディレクトリにある、なんらかの NDBM ツールやdbmmanageプログラムを使ってそのようなファイルを作ることが出来ます。
dbm:stringと一緒にマップの接頭部をFilenameとして示す。
これは検索ファイルではなく、UNIX で実行可能なプログラムです。それを使うために言語を選択して使うことができるが、しかし結果は実行可能な UNIX バイナリーでな ければなりません(すなわち、オブジェクト・コードあるいはマジックのクッキーを持つスクリプトが先頭行として'#!/path/to/interpreter'をうまくいくようにします)。
このプログラムは一度 Apache サーバの起動時に実行されていて、次にそのstdinとstdoutのファイル・ハンドルの上のエンジンを書き換える情報を出します。それぞれのマップ機能検索のために、それはstdinの上にあるニューラインによって終結されたストリングとして、検索するべきキーを受け取るでしょう。それからそれは、stdoutの上のニューラインによって終結されたストリング、またはそれがだめなら``NULL''の4文字のストリングとして、検索された値を返さなければなりません(すなわち与えられたキーに対応する値がない)。1:1 のマップを実行するような(すなわち、キー==値)平凡なプログラムもあり得ます:
#!/usr/bin/perl
$| = 1;
while (<STDIN>) {
# ...here any transformations
# or lookups should occur...
print $_;
}
|
しかし以下に気を付けて下さい:
prg:stringと一緒にそのようなマップ接頭部をFilenameとして示すこと
| プレインテキストや DBM フォーマットファイルのために、検索キーがマップファイルのmtimeまで in-core でキャッシュされるか、サーバが再起動します。このようにあらゆるリクエストのために使われるルールでマップ機能を持つことが出来ます。これは問題ではありません。なぜなら外部検索はただ一度実行するだけですから! |
RewriteBase
Syntax: RewriteBase BaseURL
Default: default is the physical directory path
Context: per-directory config
RewriteBase命令は、ディレクトリごとの書き換えに対してベースの URL を明白に設定します。以下にあるように、RewriteRuleはディレクトリごとのコンフィグファイルで使われることができます(.htaccess)。そこではそれは、ローカルに実行する。すなわち、ローカルなディレクトリの接頭部は、この処理の段階で外され、書き換えルールは残っているものだけに作用します。最後に、それは自動的に付け加えられます。
代理が新しい URL のために立ち上がる時、このモジュールはサーバの処理に URL を再導入しなければなりません。これを可能にするためには、対応する URL 接頭部、または URL ベースが何なのかを知る必要があります。デフォルトでは、この接頭部はそれ自身対応するファイルパスです。しかし、ほとんどのウェブサイトのURLsは物理的なファイル名のパスに対応していないディレクトリなので、この仮定は通常正しくないでしょう!そこで正確な URL 接頭部を指定するために、RewriteBase命令を使わなければなりません。
| それで、もしウェブサーバの URLs が物理的なファイルパスに対応していないディレクトリならば、RewriteRule命令を使いたいあらゆる.htaccessファイルでRewriteBaseを使わなければなりません。 |
Example:
以下のディレクトリごとのコンフィグファイルを仮定します:
# # /abc/def/.htaccess -- per-dir config file for directory /abc/def # Remember: /abc/def is the physical path of /xyz, i.e. the server # has a 'Alias /xyz /abc/def' directive e.g. # RewriteEngine On # let the server know that we are reached via /xyz and not # via the physical path prefix /abc/def RewriteBase /xyz # now the rewriting rules RewriteRule ^oldstuff\.html$ newstuff.html上記の例では、/xyz/oldstuff.htmlに対するリクエストが物理的なファイル/abc/def/newstuff.htmlに正確に書き換えています。
Apache ハッカーのために:
以下のリストは内部処理段階についての詳細な情報です:
Request: /xyz/oldstuff.html Internal Processing: /xyz/oldstuff.html -> /abc/def/oldstuff.html (per-server Alias) /abc/def/oldstuff.html -> /abc/def/newstuff.html (per-dir RewriteRule) /abc/def/newstuff.html -> /xyz/newstuff.html (per-dir RewriteBase) /xyz/newstuff.html -> /abc/def/newstuff.html (per-server Alias) Result: /abc/def/newstuff.htmlこれは非常に複雑に見えるが、正確な Apache の内部処理です。なぜなら、ディレクトリごとの書き換えが処理速度を遅くしているからです。それで、それが実行している時、(書き換え)リクエストは Apache kernel の中に再導入されなければなりません。しかし:これは深刻な遠周りのように見える一方、実はそうではありません。なぜなら、この再導入は Apache サーバに対して完全に内部で実行し、同じ手続きが Apache 内部の多くの他の操作によって使われているからです。それで目的と実行が正確であることが確信できます。
RewriteCond
Syntax: RewriteCond TestString CondPattern
Default: -None-
Context: server config, virtual host, per-directory config
RewriteCond命令はルール条件を定義しています。RewriteRule命令の一つかそれ以上前に
TestStringはプレインテキストに追加する、以下の拡張構造を含むストリングです:
HTTP_USER_AGENT
REMOTE_ADDR
DOCUMENT_ROOT
TIME_YEAR
API_VERSION
Special Notes:
CondPatternは状態パターン、すなわちTestStringの現在の事例に当てはまる通常表記であり、TestStringは評価されて、その時CondPatternに対して対抗させられます。
注: CondPatternは多少の追記のある標準的なExtended Regular Expressionです:
注: これらの全てのテストは、それらを無効にするための('!')ではない文字によって先に付けられます。
さらに、付加することによってCondPatternのために特別なフラッグを設定することができます。
Example:
RewriteRule命令は本当の書き換えを行なうのに有効です。この命令は、一度よりも多く実行することができます。それから、それぞれの命令が一つの書き換えルールを定義します。これらのルールの定義状態は重要です。なぜなら作動中にルールを割り当てる時、この状態が使われるからです。
Patternは現在の URL に対して割り当てられた通常表記 (for Apache 1.1.x a System V8 and for Apache 1.2.x a POSIX) であり得ます。ここでこのルールが割り当てられた時、``current''は URL の値を意味します。これはオリジナルのリクエストされた URL ではないかもしれません。なぜなら、その前にルールのいくつかの数が合致していて、それに変更を加えることが有り得るからです。
通常表記のsyntaxについてのいくつかのヒント:
更に、NOT 文字('!')は可能なパターン接頭句である。これはパターンを無効にして、言う効力を与えます。例えば:``if the current URL does NOT match to this pattern''.これは、ネガティブなパターンと合致するのがより良い、特別な場合か、または最新のデフォルトルールとして使われることができます。
Substitution of a rewriting rule is the string
which is substituted for (or replaces) the original URL for which
Pattern matched. Beside plain text you can use
既に上で書かれたように、全ての書き換えルールはSubstitutionに割り当てられます(コンフィグファイルの定義状態で)。URL はSubstitutionによって完全に置き換えられ、書き換え処理はルールがなくなるまで続きます(
'-'という特別な代用ストリングは:「代用がない!」ことを示す。愚かに聞こえるでしょうか?いいえ、いくつかの URLs にだけ合致して、代用を行なわない書き換えルールを提供する有効なものです。例えば、 代用が実行するよりも前に、割り当てられた 1 つより多くのパターンを持つことが可能なC(chain) フラッグと関連してです。
One more note: You can even create URLs in the substitution string containing
a query string part. Just use a question mark inside the substitution string
to indicate that the following stuff should be re-injected into the
QUERY_STRING. When you want to erase an existing query string, end the
substitution string with just the question mark.
確認: 所有するサーバに対する無条件の外部方向転換が、http://thishostという接頭句では働かないのは、この特徴のせいです。そのような自己方向転換を完了するためには、Rフラッグを使わなければなりません。(以下参照)
さらに、追記することによってSubstitutionのための特別なフラッグを設定することができます。
Notice: When you use this flag, make sure that the
substitution field is a valid URL! If not, you are redirecting to an
invalid location! And remember that this flag itself only prefixes the
URL with
Notice: You really have to put ProxyRequests On into your
server configuration to prevent proxy requests from leading to core-dumps
inside the Apache kernel. If you have not compiled in the proxy module,
then there is no core-dump problem, because mod_rewrite checks for
existence of the proxy module and if lost forbids proxy URLs.
あなたの判断で以下のルールを使って下さい: CGI-script によって処理されたものに作用するよりも前に CGI-scripts のいくつかの URLs を置く時はいつでも、サブリクエストの問題にぶつかる可能性は高くなります。これらの場合、このフラッグを使ってください。
注:もし URL-to-filename 翻訳を含む違ったモジュールの命令を混ぜたいのなら、このフラッグを使わなければなりません。典型的な例はmod_aliasとmod_rewrite..の使用です。
一つ例外があります:もし代用ストリングが``http://''で始まっていれば、ディレクトリの接頭句は追加されず、外部方向転換やプロキシーのスループット(もしPフラッグが使われていれば!)が働きます!
ここには全ての可能な代用の組み合わせとその意味が記述してあります:
Inside per-server configuration (httpd.conf)
Inside per-directory configuration for /somepath
Example:
上記の書き換えマップファイルは
Notice: These variables hold the URI/URL as they were initially
requested, i.e. in a state before any rewriting. This is
important because the rewriting process is primarily used to rewrite logical
URLs to physical pathnames.
Example:
$N
(1 <= N <= 9) which provide access to the grouped parts (parenthesis!) of the
pattern from the corresponding RewriteRule directive (the one
following the current bunch of RewriteCond directives).
%N
(1 <= N <= 9) which provide access to the grouped parts (parenthesis!) of the
pattern from the last matched RewriteCond directive in the current
bunch of conditions.
%{ NAME_OF_VARIABLE }
NAME_OF_VARIABLEは以下のリストのストリングスになることができます:
HTTP headers:
HTTP_REFERER
HTTP_COOKIE
HTTP_FORWARDED
HTTP_HOST
HTTP_PROXY_CONNECTION
HTTP_ACCEPT
connection & request:
REMOTE_HOST
REMOTE_USER
REMOTE_IDENT
REQUEST_METHOD
SCRIPT_FILENAME
PATH_INFO
QUERY_STRING
AUTH_TYPE
server internals:
SERVER_ADMIN
SERVER_NAME
SERVER_PORT
SERVER_PROTOCOL
SERVER_SOFTWARE
SERVER_VERSION
system stuff:
TIME_MON
TIME_DAY
TIME_HOUR
TIME_MIN
TIME_SEC
TIME_WDAY
TIME
specials:
THE_REQUEST
REQUEST_URI
REQUEST_FILENAME
IS_SUBREQ
これらの全ての変数は、類似の指名された HTTP MIME-headers、アパッチサーバのC変数や、UNIX システムのstruct tmフィールドと一致します。
Treats the CondPattern as a plain string and compares it
lexicographically to TestString and results in a true expression if
TestString is lexicographically lower then CondPattern.
Treats the CondPattern as a plain string and compares it
lexicographically to TestString and results in a true expression if
TestString is lexicographically greater then CondPattern.
Treats the CondPattern as a plain string and compares it
lexicographically to TestString and results in a true expression if
TestString is lexicographically equal to CondPattern, i.e the
two strings are exactly equal (character by character).
If CondPattern is just "" (two quotation marks) this
compares TestString against the empty string.
パス名としてTestStringを扱い、それが存在して、そしてディレクトリであるかどうかをテストします。
パス名としてTestStringを扱い、それが存在して、そして標準ファイルであるかどうかをテストします。
パス名としてTestStringを扱い、それが存在して、そして0より大きい標準ファイルであるかどうかをテストします。
パス名としてTestStringを扱い、それが存在して、そしてシンボリックリンクであるかどうかをテストします。
Checks if TestString is a valid file and accessible via all the
server's currently-configured access controls for that path. This uses an
internal subrequest to determine the check, so use it with care because it
decreases your servers performance!
Checks if TestString is a valid URL and accessible via all the server's
currently-configured access controls for that path. This uses an internal
subrequest to determine the check, so use it with care because it decreases
your servers performance!
as the third argument to the RewriteCond directive. Flags
is a comma-separated list of the following flags:
[flags]
nocase|NC' (no case)
これは状態テストを鈍感にする、すなわち拡張されたTestStringとCondPatternの 'A-Z' と 'a-z' の違いがないことです。
ornext|OR' (or next condition)
絶対的な AND の代わりに、ローカルな OR でルール条件を結合させるためにこれを使います。典型的な例:
このフラッグなしで、3 回 cond/rule に書き込まねばなりません。
RewriteCond %{REMOTE_HOST} ^host1.* [OR]
RewriteCond %{REMOTE_HOST} ^host2.* [OR]
RewriteCond %{REMOTE_HOST} ^host3.*
RewriteRule ...some special stuff for any of these hosts...
リクエストの``User-Agent:''というヘッダーによってサイトのホームページを書き換えるために、以下のものを使うことが出来ます:
解説: もしブラウザとして(それ自身が'Mozilla'と認識する)ネットスケープナビゲータを使っているなら、フレーム等を含む最大限のホームページを入手します。もし(ターミナルベースである)Lynx ブラウザを使っているなら、イメージや表等を含まない最小限のホームページを入手します。もしそれ以外のブラウザを使っているなら、標準的なホームページを入手します。
RewriteCond %{HTTP_USER_AGENT} ^Mozilla.*
RewriteRule ^/$ /homepage.max.html [L]
RewriteCond %{HTTP_USER_AGENT} ^Lynx.*
RewriteRule ^/$ /homepage.min.html [L]
RewriteRule ^/$ /homepage.std.html [L]
RewriteRule
Syntax: RewriteRule Pattern Substitution
Default: -None-
Context: server config, virtual host, per-directory config
^ Start of line
$ End of line
. Any single character
[chars] One of chars
[^chars] None of chars
? 0 or 1 of the preceding char
* 0 or N of the preceding char
+ 1 or N of the preceding char
\char escape that specific char
(e.g. for specifying the chars ".[]()" etc.)
(string) Grouping of chars (the Nth group can be used on the RHS with $N)
注意! パターンを無効にする NOT 文字を使う時、パターンにグループ化されたワイルドカードを用いることは出来ません。これが不可能なのは、グループのためにパターンが合致しなくて、中身がないからです。その結果、もし無効なパターンが使われたら、代用ストリングの$Nを使うことはできません!
後部の記述はPatternに合致したN番目のグループの内容によって置き換えられる$N to the RewriteRule pattern
%N to the last matched RewriteCond pattern
%{VARNAME})
${mapname:key|default})
$N (N=1..9)という確認です。サーバ変数は RewriteCond命令のTestStringにとって同じようなものです。マッピング機能はRewriteMap命令によって行ない、そこで明白にされます。これら 3 種類の変数は、上記リストの状態で展開されます。
Lフラッグによる明白な終端がない限りー以下参照)
注: 特別な特徴があります。http://thishost[:thisport] という代用フィールドが接頭句である時、mod_rewriteは自動的にそれを外します。この絶対的な外部方向転換の URLs の自動削除は、有効なものであり、ホストネームの部分が生じるマッピング機能と結合して使われる重要な特徴です。これを理解するには、以下の例のセクションの最初の例を見てください。
3番目としてRewriteRule命令に。Flagsは以下のフラッグのコンマで区切られたリストです:
[flags]
redirect|R[=code]' (force redirect)
Prefix Substitution
with http://thishost[:thisport]/ (which makes the new URL a URI) to
force a external redirection. If no code is given a HTTP response
of 302 (MOVED TEMPORARILY) is used. If you want to use other response
codes in the range 300-400 just specify them as a number or use
one of the following symbolic names: temp (default), permanent,
seeother.
Use it for rules which should
canonicalize the URL and gives it back to the client, e.g. translate
``/~'' into ``/u/'' or always append a slash to
/u/user, etc.
http://thishost[:thisport]/, but rewriting goes on.
Usually you also want to stop and do the redirection immediately. To stop
the rewriting you also have to provide the 'L' flag.
forbidden|F' (force URL to be forbidden)
This forces the current URL to be forbidden, i.e. it immediately sends
back a HTTP response of 403 (FORBIDDEN). Use this flag in conjunction with
appropriate RewriteConds to conditionally block some URLs.
gone|G' (force URL to be gone)
This forces the current URL to be gone, i.e. it immediately sends back a
HTTP response of 410 (GONE). Use this flag to mark no longer existing
pages as gone.
proxy|P' (force proxy)
このフラッグは代用部分にプロキシーのリクエストとして内部的に働くようにして、直ちに(例えば、書き換えルール処理がここで終了する)プロキシーモジュールを実行する。代用ストリングがアパッチプロキシーモジュールによってハンドルされることができる有効な URI(すなわち、典型的な http://)であることを確信するに違いないでしょう。もしそうでなければ、プロキシーモジュールからエラーが出ます。このフラッグはより強力なmod_proxy命令のProxyPassの実行を行なうためと、いくつかのリモートスタッフをローカルサーバの name-space にマップするために使ってください。
last|L' (last rule)
ここで書き換え処理を終了して、これ以上の書き換えルールを追加しません。これは perl のlastコマンドやC言語のbreakコマンドと一致します。このフラッグは、悪化するかもしれない以下のルールによって更に書き換えが行われることから、現在の書き換えられた URL を防ぐために使われます。例えば、ルートパスの URL('/')を実在するものに書き換えるために使います。すなわち、'/e/www/'です。
next|N' (next round)
書き換え処理を再実行します(最初の書き換えルールを再び始めます)。ここで一致するための URL はオリジナルの URL に対してではなく、最新の書き換えルールからの URL です。これはパールのnextコマンドやC言語のcontinueコマンドと一致します。このフラッグは書き換え処理を再実行するため、すなわち直ちにループのトップへ移動するために使います。
デッドループを作らないように気を付けて下さい!
chain|C' (chained with next rule)
このルールは次のルール(それ自身もまた以下のルール等とつなぐことができる)と現在のルールをつなぎます。これは以下の効果があります:もしルールが一致していれば、普通に処理を行ない、フラッグは効果を発揮しません。もしルールが一致していなければ、全ての以下につながっているルールはスキップされます。例えば、外部方向転換を起こさせた時(``.www''の部分で起こすべきではない!)、ディレクトリごとのルール設定の中で``.www''部分を外すためにこれを使います。
type|T=mime-type' (force MIME type)
mime-typeであるターゲットファイルの MIME-type に作用します。例えば、``application/x-httpd-cgi''の MIME type を持つマップされたディレクトリの中にある全てのファイルに内部的に働く古いmod_alias命令であるScriptAliasをシミュレイトするために使うことが出来ます。
nosubreq|NS' (used only if no internal sub-request)
もし現在のリクエストが内部のサブリクエストであれば、このフラッグは書き換えルールをスキップするために書き換えエンジンに作用します。例えば、mod_includeが実行可能なディレクトリのデフォルトファイル(index.xxx)についての情報を探そうとしている時、サブリクエストはアパッチで内部的に発生します。サブリクエストでは、もし完了したルールの設定を追加されると、有効ではなく、時々失敗の原因となります。いくつかのルールを排除するためにこのフラッグを使います。
qsappend|QSA' (query string
append)
This flag forces the rewriting engine to append a query
string part in the substitution string to the existing one instead of
replacing it. Use this when you want to add more data to the query string
via a rewrite rule.
passthrough|PT' (pass through to next handler)
このフラッグはfilename領域の値に対して、内部のrequest_rec構造のuri領域を設定するために書き換えエンジンに作用します。このフラッグはちょうど、Alias, ScriptAlias, Redirect等の他の URI-to-filename 翻訳からの命令によるRewriteRule命令の post-process 出力を可能にするハックです。セマンティクス を示すありふれた例:もし/abcを/defにmod_rewriteの書き換えエンジンによって、その時 /defを/ghiにmod_aliasで書き換えたいのなら:
RewriteRule ^/abc(.*) /def$1 [PT]
Alias /def /ghi
もしmod_rewriteがその作業を無事に行なう時PTフラッグを省略すれば、すなわち翻訳が行なうべきフルの API-compliant の URI-to-filename としてuri=/abc/...をfilename=/def/...に書き換えます。その時mod_aliasは、働かない URI-to-filename 移行を行なおうとします。
アパッチハッカーのために:
もし現在のアパッチ API が URI-to-filename フックに追加する filename-to-filename フックを持っていれば、その時このフラッグは必要ありません!しかしそのようなフックなしでは、このフラッグはただの解答です。アパッチグループはこの問題を討議し、アパッチversion 2.0 にそのようなフックを追加します。
skip|S=num' (skip next rule(s))
このフラッグは現在のルールが一致している時、連続の次のnumルールをスキップするように働きます。仮の if-then-else 構造を作るためにこれを使います: then-clause の最新のルールが、N が else-clause のルールの数字であるskip=Nになります(これは'chain|C' フラッグとは違います!)
env|E=VAR:VAL' (set environment variable)
This forces an environment variable named VAR to be set to the
value VAL, where VAL can contain regexp backreferences
$N and %N which will be expanded. You can use this flag
more than once to set more than one variable. The variables can be later
dereferenced at a lot of situations, but the usual location will be from
within XSSI (via <!--#echo var="VAR"-->) or CGI (e.g.
$ENV{'VAR'}). But additionally you can also dereference it in a
following RewriteCond pattern via %{ENV:VAR}. Use this to strip
but remember information from URLs.
確認:サーバごとのコンフィグレーションファイルの完了した URL にPatternが追加されたことを決して忘れないで下さい。しかし、ディレクトリごとのコンフィグレーションファイルでは、代用が行われた後、ディレクトリごとの接頭句(いつも特定のディレクトリとっては同じ物!)がパターンの一致で自動的にremovedされ、自動的にaddedされます。この特徴は多くの種類の書き換えの基本になっています。なぜなら、この接頭句を外すことなしでは、常に実行可能とは限らない親ディレクトリと一致しなければならないからです。
注意!ディレクトリごとのコンフィフレーションファイルの書き換えエンジンを可能にするためには、これらのファイルで``RewriteEngine On''と可能になった``Option FollowSymLinks''を設定する必要があります。もし管理者がユーザディレクトリのFollowSymLinksの override を不可能にしていれば、書き換えエンジンを使うことはできません。この制限はセキュリティ上必要です。
for request ``GET /somepath/pathinfo'':
Given Rule Resulting Substitution
---------------------------------------------- ----------------------------------
^/somepath(.*) otherpath$1 not supported, because invalid!
^/somepath(.*) otherpath$1 [R] not supported, because invalid!
^/somepath(.*) otherpath$1 [P] not supported, because invalid!
---------------------------------------------- ----------------------------------
^/somepath(.*) /otherpath$1 /otherpath/pathinfo
^/somepath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) /otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^/somepath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^/somepath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^/somepath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^/somepath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^/somepath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
(i.e. file .htaccess in dir /physical/path/to/somepath containing
RewriteBase /somepath)
for
request ``GET /somepath/localpath/pathinfo'':
Given Rule Resulting Substitution
---------------------------------------------- ----------------------------------
^localpath(.*) otherpath$1 /somepath/otherpath/pathinfo
^localpath(.*) otherpath$1 [R] http://thishost/somepath/otherpath/pathinfo
via external redirection
^localpath(.*) otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) /otherpath$1 /otherpath/pathinfo
^localpath(.*) /otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) /otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) http://thishost/otherpath$1 /otherpath/pathinfo
^localpath(.*) http://thishost/otherpath$1 [R] http://thishost/otherpath/pathinfo
via external redirection
^localpath(.*) http://thishost/otherpath$1 [P] not supported, because silly!
---------------------------------------------- ----------------------------------
^localpath(.*) http://otherhost/otherpath$1 http://otherhost/otherpath/pathinfo
via external redirection
^localpath(.*) http://otherhost/otherpath$1 [R] http://otherhost/otherpath/pathinfo
via external redirection
(the [R] flag is redundant)
^localpath(.*) http://otherhost/otherpath$1 [P] http://otherhost/otherpath/pathinfo
via internal proxy
We want to rewrite URLs of the form
into
/ Language
/~ Realname
/.../ File
/u/ Username
/.../ File
. Language
/anywhere/map.real-to-userの下に置いてあります。それから、Apache サーバのコンフィグレーションファイルに以下の行を追加することだけをしなければなりません:
RewriteLog /anywhere/rewrite.log
RewriteMap real-to-user txt:/anywhere/map.real-to-host
RewriteRule ^/([^/]+)/~([^/]+)/(.*)$ /u/${real-to-user:$2|nobody}/$3.$1
Additional Features
Environment Variables
This module keeps track of two additional (non-standard) CGI/SSI environment
variables named SCRIPT_URL and SCRIPT_URI. These contain
the logical Web-view to the current resource, while the standard CGI/SSI
variables SCRIPT_NAME and SCRIPT_FILENAME contain the
physical System-view.
SCRIPT_NAME=/v/sw/free/lib/apache/global/u/rse/.www/index.html
SCRIPT_FILENAME=/u/rse/.www/index.html
SCRIPT_URL=/u/rse/
SCRIPT_URI=http://en2.en.sdm.de/u/rse/
Apache HTTP Server Version 1.3
The English original manual is here.