PHP

FastCGI for IIS7.0のアップデート

件のIIS用FastCGIモジュールがREQUEST_URIなどのサーバー変数をUTF-8でやり取りできない問題の続き。

IIS5.1、IIS6についてはVer1.5 RTW+レジストリ操作で解決しましたが、IIS7.xにいては対応がまだでした。

が、やっとIIS7.0についてアップデートが提供されました。

http://blogs.iis.net/ruslany/archive/2010/03/10/important-update-for-iis-7-0-fastcgi-module.aspx

Windows7やWindowsServer2008R2のIIS7.5用FastCGIのアップデートはまだだがな!

なお、各OSでのFastCGI for IISの状況はこちら。

http://ruslany.net/2010/02/fastcgi-module-differences-across-iis-versions/

Using UTF-8 encoding for server variable valuesがIIS7.5だけNoという。

いやこれ、実質URIにマルチバイトを含めないわけで、非英語圏のアプリケーション的には致命度が半端ないんですが…

FastCGI 1.5 for IIS6でREQUEST_URIが文字化けする件の解決

こちらのエントリで書いた、FastCGI for IISでのREQUEST_URIの文字化け問題ですが、iis.netのページにこんな情報がありました。

Configure the FastCGI Extension for IIS 6.0

Using UTF-8 encoding for server variables

By default, FastCGI extension uses ASCII encoding when setting server variables that are used by PHP. When requested URL contains non-ASCII characters, then server variables that derive their values from the requested URL string may be set incorrectly. PHP applications that rely on those server variables may not work because of that.

To prevent this the FastCGI extension can be configured to use UTF-8 encoding when setting server variables. To configure FastCGI to use UTF-8 encoding for a particular set of server variables, use the REG_MULTI_SZ registry key FastCGIUtf8ServerVariables and set its value to a list of server variable names, for example:

reg add HKEY_LOCAL_MACHINE\System\CurrentControlSet\Services\w3svc\Parameters /v FastCGIUtf8ServerVariables /t REG_MULTI_SZ /d REQUEST_URI\0PATH_INFO

The above example will configure FastCGI extension to use UTF-8 encoding when setting REQUEST_URI and PATH_INFO server variables.

After setting the registry key restart the IIS by using the iisreset command.

Warning: using UTF-8 encoding for server variables may affect how PHP core and PHP applications work. Make sure to verify that applications work as expected after the registry key has been changed.

1月にやっとリリースされたRTW版で追加されたオプションのようです。要は、デフォ設定だとREQUEST_URIやPATH_INFOをUTF-8でやりとり出来ないと。

というわけなので、コマンドラインで上記レジストリエントリへの追加をして、IISのサービスを再起動して完了。

Wordpressのclasses.phpを修正していたのを戻して、エントリ単品の記事へ正常にアクセス出来る事が確認できました。

しかしなんでデフォでこんな仕様なんだろう…

FastCGI拡張forIISでREQUEST_URIが文字化けする

Wordpressをアップデートしたら元に戻ってしまったのでメモ。

URLのパスや引数の名前に含まれるURLエンコード部分の文字列が、なぜかShift-JISで飛んできます。URLエンコード前の文字列が日本語などでなければ大丈夫。

どっかの設定が悪いのかなんなのか。変な設定とかしてないんですけどねぇ。

Wordpressの場合の対処はこんな感じ。

classes.phpの152行目あたりにこんなコードを追記する。

$_SERVER['REQUEST_URI'] = mb_convert_encoding($_SERVER['REQUEST_URI'],’UTF-8′,’SJIS’);
$_SERVER['PATH_INFO'] = mb_convert_encoding($_SERVER['PATH_INFO'],’UTF-8′,’SJIS’);

Windows7をお持ちの方は、WebPlatform Instaler 2.0で、マウスだけでインストール出来るのでお試しあれ。