なんか2011年頃にも書いてあったんだけど、動かないし記述がおかしい気がする。
というわけで2015年版(Apache 2.4 で確認)で再度。
キモは VirtualHost コンテキストで書くことだった
(そうしないと ScriptAlias に先にとられてドキュメントルート側のディレクトリに Rewrite の処理がまわってこない)。
ScriptAlias /cgi-bin/ "/var/www/www.example.jp/cgi-bin/" # 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] # Everything is transferred to the handler script # except actually available files in the document root. RewriteCond %{DOCUMENT_ROOT}/%{REQUEST_FILENAME} !-f RewriteRule ^(.*)$ /cgi-bin/handler.cgi/$1 [PT,QSA,L] </IfModule>
昔設定したやつとか、どうして意図通り動いたのか今ではワカンネ……。