在http-equiv元标记内将内容类型设置为utf-8时获取重复的http请求

时间:2011-11-21 12:25:00

标签: html apache utf-8 http-headers content-type

我在我的网站上发现我两次收到http请求。我正在使用apache2服务器。例如,我访问index.php,我得到2个不同的index.php标头请求(图像和CSS文件只请求一次),因此页面提供两次,任何数据库操作都完成两次。

我发现这是由meta标签http-equiv引起的。当我将content-type属性设置为UTF-8时,我得到这种行为,删除标记或将其设置为其他编码类型(例如ISO-8859-1)可以消除此问题。

这是该元标记的html代码:

<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>

以下是Http Headers Live插件捕获的已发送和已接收的标头,显示重复的请求:

http://oposiziones.dev/



GET / HTTP/1.1

Host: oposiziones.dev

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: es-es,en-us;q=0.7,en;q=0.3

Accept-Encoding: gzip, deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Connection: keep-alive

Referer: http://oposiziones.dev/error-53_q0.html

Cookie: PHPSESSID=jeup12fp5lpoo5t9k052qt7tl7



HTTP/1.1 200 OK

Date: Mon, 21 Nov 2011 11:53:25 GMT

Server: Apache/2.2.20 (Ubuntu)

X-Powered-By: PHP/5.3.6-13ubuntu3.2

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Vary: Accept-Encoding

Content-Encoding: gzip

Content-Length: 6496

Keep-Alive: timeout=5, max=100

Connection: Keep-Alive

Content-Type: text/html




http://oposiziones.dev/



GET / HTTP/1.1

Host: oposiziones.dev

User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:7.0.1) Gecko/20100101 Firefox/7.0.1

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: es-es,en-us;q=0.7,en;q=0.3

Accept-Encoding: gzip, deflate

Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7

Connection: keep-alive

Referer: http://oposiziones.dev/error-53_q0.html

Cookie: PHPSESSID=jeup12fp5lpoo5t9k052qt7tl7



HTTP/1.1 200 OK

Date: Mon, 21 Nov 2011 11:53:26 GMT

Server: Apache/2.2.20 (Ubuntu)

X-Powered-By: PHP/5.3.6-13ubuntu3.2

Expires: Thu, 19 Nov 1981 08:52:00 GMT

Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0

Pragma: no-cache

Vary: Accept-Encoding

Content-Encoding: gzip

Content-Length: 6385

Keep-Alive: timeout=5, max=99

Connection: Keep-Alive

Content-Type: text/html

有人知道如何解决这个问题吗?我需要保留UTF-8编码,因为我的数据库数据设置为UTF-8,所有内容都应编码为UTF-8。

我猜这是一个apache编码问题,但不知道为什么会这样。

提前致谢!

1 个答案:

答案 0 :(得分:0)

我没有找到原因,但是,我通过将此指令添加到apache配置文件来解决了这个问题。

添加到配置文件/etc/apache2/conf.d/charset AddDefaultCharset UTF-8

此选项会覆盖任何http-equiv charset元标记,因此内容始终以utf-8发送。如果您的所有内容都应以该编码方式发送,则没有问题,但如果您使用多种类型的编码,则不会成为解决方案。

您可以将此配置指令移动到.htaccess,这样它就不会影响整个服务器,只会影响您想要的文件夹/站点。

相关问题