如何在 HTTP Content-Type 响应头中指定字符集? [英] How to specify the character set in the HTTP Content-Type response header?

查看:36
本文介绍了如何在 HTTP Content-Type 响应头中指定字符集?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Google 的 Page Speed 应用测试了我的网站,其中一个建议是指定HTTP Content-Type 响应标头中的字符集声称它比元标记中的要好.

I had my site tested with the Page Speed app from Google and one of the suggestions was to specify the character set in the HTTP Content-Type response header claiming it was better than just in a meta tag.

以下是我理解我需要写的内容:内容类型:文本/html;charset=UTF-8

Here's what I understand I need to write: Content-Type: text/html; charset=UTF-8

..但是我应该把这个放在哪里?我在共享服务器上.

..but where exactly should I put this? I'm on a shared server.

谢谢!

推荐答案

Apache:添加到根目录下的 .htaccess 文件中:

Apache: add to your .htaccess file in root directory:

AddDefaultCharset UTF-8

它将从此修改标题:

内容类型文本/html

...到这个:

内容类型文本/html;charset=UTF-8

nginx [doc] [serverfault Q]

server {
   # other server config...
   charset utf-8;
}

添加 charset utf-8;server 块(并重新加载 nginx 配置)

add charset utf-8; to server block (and reload nginx config)

这篇关于如何在 HTTP Content-Type 响应头中指定字符集?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆