gpt4 book ai didi

apache - 在 ErrorDocument 消息中设置字符集

转载 作者:行者123 更新时间:2023-12-02 07:41:20 25 4
gpt4 key购买 nike

我有一个 .htaccess 文件,如下所示:

AddDefaultCharset utf-8
AddCharset utf-8 .html
Order Allow,Deny
ErrorDocument 403 "Error 403 - Esta ubicación no es pública"

文件本身编码为 UTF-8。然而,Apache 坚持声明 ISO-8859-1,并且错误消息被破坏:

HTTP/1.1 403 Forbidden
Date: Fri, 29 Nov 2013 10:06:25 GMT
Server: Apache/2.4.6 (Win32) OpenSSL/1.0.1e PHP/5.5.6
Content-Length: 42
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive
Content-Type: text/html; charset=iso-8859-1

如果我在浏览器中手动将编码更改为 UTF-8,文本看起来是正确的。

网站已被授予所有权限:

<VirtualHost *:80>
ServerName tmp
DocumentRoot "D:/tmp"

<Directory "D:/tmp">
AllowOverride All
Require all granted
</Directory>
</VirtualHost>

...Apache 日志中没有任何相关内容。

我错过了什么?

最佳答案

问得好!我必须说。我必须挖掘所有资源并阅读大量手册才能找到此行为的原因。

这似乎是一种已知行为,但官方手册中没有很好地介绍。最后,我在this Apache manual中找到了它的一个引用。 :

suppress-error-charset

Available in versions after 2.0.54

When Apache issues a redirect in response to a client request, the response includes some actual text to be displayed in case the client can't (or doesn't) automatically follow the redirection. Apache ordinarily labels this text according to the character set which it uses, which is ISO-8859-1.

However, if the redirection is to a page that uses a different character set, some broken browser versions will try to use the character set from the redirection text rather than the actual page. This can result in Greek, for instance, being incorrectly rendered.

Setting this environment variable causes Apache to omit the character set for the redirection text, and these broken browsers will then correctly use that of the destination page.

这正是您在 header 中看到的 charset=iso-8859-1 的行为。

<小时/>

如何修复:

你的 .htaccess 代码如下:

# set desired env variable to suppress iso-8859-1 charset
SetEnvIf Host ^ suppress-error-charset

# set desired 403 message with desired charset
ErrorDocument 403 "<html><head><meta http-equiv='Content-Type' content='text/html; charset=utf-8'></head><body>Error 403 - Esta ubicación no es pública</body></html>"

请注意,SetEnvIf Host ^ 是一个始终成立的条件,因此 suppress-error-charset> 将始终被设置。我仅使用 .htaccess 中的这两行进行了测试,并在浏览器中显示了正确的错误消息。

关于apache - 在 ErrorDocument 消息中设置字符集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20283301/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com