1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Apache のコンテンツネゴシエーションによる言語振り分けについて

Posted at

言語振り分け設定

httpd.conf 追記

# vim /etc/httpd/conf/httpd.conf
<Directory "/var/www/html">

    Options +MultiViews
    DirectoryIndex index

Apache再起動

# service httpd restart

ファイル用意

# ls -l /var/www/html/
-rw-r--r-- 1 root root 17 2015-02-27 00:38 index.html.en
-rw-r--r-- 1 root root 34 2015-02-27 00:37 index.html.ja

確認

# curl -H 'Accept-Language: ja, en;q=0.8' localhost
# curl -H 'Accept-Language: en, ja;q=0.8' localhost
# curl -H 'Accept-Language: ja-jp, ja, en-us, en;q=0.8' localhost

補足

「ja-jp」「en-us」はデフォルトのApacheの設定に含まれていないため、適宜追加する。

# grep AddLanguage /etc/httpd/conf/httpd.conf
# DefaultLanguage and AddLanguage allows you to specify the language of
# language code is pl) may wish to use "AddLanguage pl .po" to
AddLanguage ca .ca
AddLanguage cs .cz .cs
AddLanguage da .dk
AddLanguage de .de
AddLanguage el .el
AddLanguage en .en
AddLanguage eo .eo
AddLanguage es .es
AddLanguage et .et
AddLanguage fr .fr
AddLanguage he .he
AddLanguage hr .hr
AddLanguage it .it
AddLanguage ja .ja
AddLanguage ko .ko
AddLanguage ltz .ltz
AddLanguage nl .nl
AddLanguage nn .nn
AddLanguage no .no
AddLanguage pl .po
AddLanguage pt .pt
AddLanguage pt-BR .pt-br
AddLanguage ru .ru
AddLanguage sv .sv
AddLanguage zh-CN .zh-cn
AddLanguage zh-TW .zh-tw

追加する(Apache要再起動)

AddLanguage ja-jp .ja
AddLanguage en-us .en

追加例

# curl -H 'Accept-Language: en-us, ja, en;q=0.8' localhost
Japanese contents

<-- Add httpd.conf 「AddLanguage en-us .en」-->
# service httpd restart

# curl -H 'Accept-Language: en-us, ja, en;q=0.8' localhost
English contents

※本設定は「.htaccess」に記載することも可能。

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?