我想在Apache上显示Shift_JIS字符编码

准备

# docker run --privileged -p 8080:80 --rm centos:centos7 /sbin/init
# docker exec -it `docker ps -q` /bin/bash
[root@388335783ce8 /]# yum install -y httpd
[root@388335783ce8 /]# systemctl start httpd
[root@388335783ce8 /]# mkdir /var/www/html/sjis
[root@388335783ce8 /]# vi /var/www/html/sjis/index.html <- Shift-JISのテキストを置く
<!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Shift_JIS">
<title>Shift_JIS</title>
</head>
<body>
日本語が化けないことを期待
</body>
</html>

处理

由于标题标签中设置了charset=UTF-8,浏览器会优先使用标题标签而不是meta标签,因此会出现乱码。

[root@388335783ce8 /]# curl localhost/sjis/ -I
Content-Type: text/html; charset=UTF-8
<Directory /var/www/html/sjis>
    AddDefaultCharset Off
</Directory>
[root@388335783ce8 /]# systemctl reload httpd
[root@388335783ce8 /]# curl localhost/sjis/ -I
Content-Type: text/html
广告
将在 10 秒后关闭
bannerAds