获得重复的http请求设置内容类型为UTF-8时,内部HTTP-EQUIV meta标签 [英] Getting duplicate http requests when setting content-type to utf-8 inside http-equiv meta tag

查看:168
本文介绍了获得重复的http请求设置内容类型为UTF-8时,内部HTTP-EQUIV meta标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的网站,我得到了http请求两次找到。我使用的Apache2服务器。比如我访问的index.php,我得到的index.php(图像和CSS文件只要求一次)2个不同的头部的请求,所以页面被两次,任何数据库操作完成两次。

I've found in my site that I'm getting the http requests twice. I'm using an apache2 server. For example I visit index.php and I get 2 different header requests for index.php (images and CSS files are only requested once), so the page is served twice and any database operation is done twice.

我发现这是由元标记,HTTP的当量造成的。当我的内容类型属性设置为UTF-8我得到这个行为,删除标签或将其设置为另一种编码类型(如ISO-8859-1)消除了这个问题。

I've found that this is being caused by the meta tag, http-equiv. When I set the content-type attribute to UTF-8 I get this behaviour, removing the tag or setting it to another encoding type (such as ISO-8859-1) eliminates this issue.

这是HTML code为元标记:

This is the html code for that meta-tag:

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

下面是由HTTP标头直播插件抓住了发送和接收头,,显示的重复请求:

Here are the sent and received headers caught by Http Headers Live plugin, that show the duplicate request:

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,一切都应该是EN coded到UTF-8。

Anybody with an idea on how to solve this? I need to keep the UTF-8 encoding because my database data is set to UTF-8, and everything should be encoded to UTF-8.

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

I guess this is an apache encoding issue, but have no idea why this happens.

在此先感谢!

推荐答案

我没有找到为什么发生这一点,但我加入这个指令Apache配置文件解决了问题。

I didn't find why is happening this but, I solved the issue by adding this directive to the apache configuration file.

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

Added to config file /etc/apache2/conf.d/charset AddDefaultCharset UTF-8

这个选项将覆盖任何HTTP-当量的charset meta标签,所以内容总是以UTF-8发送。这是没有问题的,如果所有的内容应该在编码发送,但如果使用多种类型的编码将不会是一个解决办法。

This option overrides any http-equiv charset meta tag, so the content is always sent in utf-8. This is no problem if all your content should be sent in that encoding, but won't be a solution if you use several types of encoding.

您可以在此配置指令转移到你的.htaccess,因此不会影响整个服务器,只是你想要的文件夹/站点。

You can move this configuration directive to your .htaccess so it doesn't affect the whole server, just the folder/site you want to.

这篇关于获得重复的http请求设置内容类型为UTF-8时,内部HTTP-EQUIV meta标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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