mod_rewriteのRewriteRuleでクエリを引き継ぎたい場合は、QSAフラグが使えることを最近知りました。 たとえば次のようなURLをリクエストします。 http://example.com/status/fkoji?count=10 サーバ側で定義している RewriteRule は次のようなものです。 RewriteRule /([^/]+)/([^/]+) index.php?controller=$1&user_name=$2 [L] この場合、リライト後のURLは、 http://example.com/index.php?controller=status&user_name=fkoji となって元々存在していた count クエリが消えてしまって困ります。 こういう場合にQSAフラグを使うことができます。 RewriteRule /([^/]+)/([^/]+)
このように便利な Rewrite 機能は、個別ディレクトリに設置された .htaccess にも指定することができる。しかし、.htaccess に書けるのは RewriteEngine, RewriteBase, RewriteCond, RewriteRule だけで、ロギングに関する指定子などは書けないし、色々と注意すべきハマリ点がある。ここではそれらを一気に解説しようと思う。これは管理者になれない(=httpd.confを編集できない)一般ユーザにとっては重要な情報になるだろうね。 .htaccess は個別の公開ディレクトリに設置されて、細かい制御を出来るもので、よく個別ディレクトリにアクセス制限を入れたりするのに使う。しかし、いくつかの Apache 指定子は、ここにも書けるし、幸いなことに Rewrite機能(正確には mod_rewrite.so)は、この .htacces
mod_rewriteとは Apacheのモジュールのひとつで、アクセスURLを正規表現で書き換えることができます。リダイレクト処理を行うのに便利なモジュールです。 モジュールの解説ドキュメントによれば URLを操作するためのスイス製のアーミーナイフ と例えられるほど、非常に複雑な処理を行えます。 URLからURLへ、同一サーバ内URLだろうが、別サーバURLだろうが問いません。 引数を含む動的URLを通常のHTMLファイルのような静的URLに見せることも可能です。 素晴らしく詳細なマニュアルもありますが、機能が多いだけに情報量が多く読むのも面倒だと思いますので、ここでは、mod_rewriteを使用すると便利な場面を想定して具体的に解説してみたいと思います。 mod_rewriteの基本 ひとまず、mod_rewriteはApacheのモジュールです。インストールされていなければ、サーバ
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
処理を実行中です
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く