http 标头指定字符编码 iso-8859-1 而不是 utf-8 时出现问题?
我最近设计了一个包含德语和荷兰语字符的网站,我希望该页面使用字符编码 utf-8。
我添加了 xml 声明:
<?xml version="1.0" encoding="UTF-8"?>
和元标记:
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
当我在线查看网站时,德语文本中的特殊字符无法正确显示。当我尝试使用 w3c 验证器验证页面时,我收到以下警告:
HTTP 标头中指定的字符编码 (iso-8859-1) 与 XML 声明中的值 (utf-8) 不同。我将使用 HTTP 标头 (iso-8859-1) 中的值。
这是服务器问题吗?只是我已将相同的文件上传到我的不同服务器,并且页面使用 utf-8 正确显示。
任何有关我如何将页面编码为 utf-8 的帮助或建议将不胜感激。
我被难住了!
感谢 jason,我找到了一个名为 mod_mime-defaults.conf 的文件,
该文件包含以下内容:
# AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1
如果我删除 AddDefaultCharset UTF-8 之前的 #,您认为这会有帮助吗?或者可以在 AddDefaultCharset ISO-8859-1 之前添加 #。
我尝试编辑此文件,但我认为我没有权限。嗯...?
I have recently designed a website that contains German and Dutch characters and I would like the page to use character encoding utf-8.
I have added the xml declaration:
<?xml version="1.0" encoding="UTF-8"?>
and the meta tag:
<meta http-equiv="content-type" content="text/html; charset=UTF-8" />
When I viewed the website on-line, the special characters found in the German text were not displaying correctly. When I tried validating the page with the w3c validator, I got the following warning:
The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the XML declaration (utf-8). I will use the value from the HTTP header (iso-8859-1).
Is this a server issue? It's just that I have uploaded the same files to a different server of mine and the pages display correctly there using utf-8.
Any help or advice regarding how I would go about getting the page to encode as utf-8 would be greatly appreciated.
I'm stumped!
Thanks to jason, I found a file named mod_mime-defaults.conf
this file contains the following:
# AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1
If I remove the # from before AddDefaultCharset UTF-8, do you think this will help? Or maybe add a # before AddDefaultCharset ISO-8859-1.
I tried editing this file, but I don't think I have permission. Hmmm...?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这可能是服务器问题。
如果您使用 Apache,请检查 Apache 配置文件(通常位于 *nix 服务器上的 /etc/httpd/conf/httpd.conf),以获取
AddDefaultCharset
的值。此设置指定所提供的所有内容的默认值。如果它被注释掉,则意味着它将依赖浏览器的或 META 设置来确定字符集。
This could be a server issue.
If you are using Apache check the Apache config file usually located here /etc/httpd/conf/httpd.conf on a *nix server, for the value of
AddDefaultCharset
.This setting specifies the default for all content served. If it is commented out, that means it will rely on the browser's, or META settings to determine the Charset.
HTML 元标记与 HTTP 响应标头不同。您需要在HTTP响应头中设置字符编码。根据您的问题历史记录,您正在使用 PHP - 或者至少熟悉它 -,因此这里有一个针对 PHP 的示例,说明如何执行此操作。
在回显任何字符之前,请将以下行放入 PHP 文件中。
另请参阅:
与问题无关:您不应在 HTML 页面上放置 XML 声明。这会引发其他麻烦。
The HTML meta tag is not the same as the HTTP response header. You need to set the character encoding in the HTTP response header. As per your question history you're using PHP -or are at least familiar with it-, so here's a PHP targeted example of how to do it.
Put the following line in the PHP file before you echo any character.
See also:
Unrelated to the problem: you shouldn't put a XML declaration on a HTML page. This is recipe for other sort of trouble.
我将 charset=UTF-8 更改为 charset=iso-8859-1,警告消失了。
I changed charset=UTF-8 to charset=iso-8859-1, and the warning went away.