なんか微妙な部分があったのと
Apache の ErrorDocument の指定をスクリプトに結びつけようとしたら無限ループしたので微妙に修正。
# Following Rewrite settings must be in VirtualHost context exactly, # not Directory context or .htaccess. <IfModule mod_rewrite.c> RewriteEngine on # It hides the specified script directory as 404-Not-Found, # also it's children are hidden too. RewriteCond %{REQUEST_URI} ^/cgi-bin(:?$|/.*$) RewriteRule ^(.*)$ - [R=404,L] # Direct access to error documents is disallowed too. RewriteCond %{REQUEST_URI} ^/error(:?$|/.*$) RewriteCond %{ENV:REDIRECT_STATUS} ^$ RewriteRule ^(.*)$ - [R=404,L] # Everything is transferred to the handler script # except actually available files in the document root. RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f RewriteRule ^/(.*)$ /cgi-bin/index.cgi/$1 [PT,QSA,L,NS] </IfModule> ScriptAlias /cgi-bin/ "/var/www/www.example.jp/cgi-bin/" ErrorDocument 404 /error/404
あとログ見てたらサブリクエストがたくさん発生していたので
DirectoryIndex (何も書かない)
とか
Options -Multiviews -Indexes
とかも書いてみた。
が、もしかしたらそもそも
http://stackoverflow.com/questions/9618865/mod-rewrite-mysterious-subreq
ここに書いてあるように %{IS_SUBREQ} で制御できたのかもしれない。
今回は Apache が エラードキュメントには REDIRECT_STATUS を設定してくれる事に依存してる。
そういえばあとスクリプト側が今まで REQUEST_URI をみてたんだけど、
これだと ErrorDocument の時も元のままの変わらないので
PATH_INFO をみるように変更した。
通常は PATH_INFO は REQUEST_URI を URL デコードしたものになるはずらしい。
さらにそういえば RewriteLog が廃止されてたので
LogLevel debug rewrite:trace8
こんなふうに指定した。