LocationMatch の設定
httpd.conf
<LocationMatch "^/test/.*index.html$">
AddDefaultCharset Shift_JIS
</LocationMatch>
ファイル構成
htdocs
│ index.html
│
├─hoge
│ └─test
│ index.html
│
└─test
│ index.htm
│ index.html
│
└─sub
index.htm
index.html
テスト用のシェル
#!/bin/sh
test() {
echo $1
wget -S $1 -O testcontents.html -o test.html
echo -n " "
grep 'Content-Type' test.html | sed 's/.*charset=//'
}
test "http://localhost:8080/"
test "http://localhost:8080/index.html"
test "http://localhost:8080/test/"
test "http://localhost:8080/test/index.html"
test "http://localhost:8080/test/index.htm"
test "http://localhost:8080/test/sub/"
test "http://localhost:8080/test/sub/index.html"
test "http://localhost:8080/test/sub/index.htm"
test "http://localhost:8080/hoge/test/index.html"
実行結果
$ sh test.sh
http://localhost:8080/
UTF-8
http://localhost:8080/index.html
UTF-8
http://localhost:8080/test/
Shift_JIS
http://localhost:8080/test/index.html
Shift_JIS
http://localhost:8080/test/index.htm
UTF-8
http://localhost:8080/test/sub/
Shift_JIS
http://localhost:8080/test/sub/index.html
Shift_JIS
http://localhost:8080/test/sub/index.htm
UTF-8
http://localhost:8080/hoge/test/index.html
UTF-8
結果
<LocationMatch "^/test/.*index.html$">
AddDefaultCharset Shift_JIS
</LocationMatch>
htdocs
│ index.html ×
│
├─hoge
│ └─test
│ index.html ×
│
└─test ○
│ index.htm ×
│ index.html ○
│
└─sub ○
index.htm ×
index.html ○