0
0

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 3 years have passed since last update.

ApacheでShift_JISを表示したい

Posted at

準備

# 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のテキストを置く
/var/www/html/sjis/index.html
<!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
/etc/httpd/conf.d/sjis.conf
<Directory /var/www/html/sjis>
    AddDefaultCharset Off
</Directory>
[root@388335783ce8 /]# systemctl reload httpd
[root@388335783ce8 /]# curl localhost/sjis/ -I
Content-Type: text/html
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?