Apache type-map の設定
ブラウザの言語設定によりページを切り替える方法として Apacheでは
type-map の設定を行える。モジュールは標準の mod_negotiation である。
前提条件
- デフォルトは日本語(Shift_JIS)。
- とりあえず英語を用意。
- SSI(Server Side Include)の設定もしている。
設定内容
# vi /usr/local/apache2/conf/httpd.conf <Directory "/home/foobar/public_html/test/type-map"> Options FollowSymLinks IncludesNoExec AddType text/html .shtml AddOutputFilter INCLUDES .shtml # set in the global part. # AddHandler type-map var <IfModule mod_dir.c> DirectoryIndex index.html.var index.shtml index.html </IfModule> </Directory> # /usr/local/apache2/bin/httpd -l mod_negotiation.c があることを確認。 # /usr/local/apache2/bin/apachectl configtest # /usr/local/apache2/bin/apachectl graceful # cd /home/foobar/public_html/test/type-map # vi index.html.var URI: index-en.shtml Content-language: en Content-type: text/html URI: index-en.shtml Content-language: en-us Content-type: text/html URI: index-en.shtml Content-language: en-gb Content-type: text/html URI: index.shtml Content-language: ja Content-type: text/html;charset=Shift_JIS # vi index.shtml 日本語(Shift_JIS)のhtml(Server Side Include構文も含む)を記述。 # vi index-en.shtml 英語のhtml(Server Side Include構文も含む)を記述。
この設定により、http://www.example.jp/~foobar/test/type-map/ としてアクセスすると、 index.html.var がない場合は index.shtml を見にいくので日本語サイトとしてはこれがいいだろう。
en-us, en-gbはIE7用。enという言語がデフォルトではないみたい。