本文介绍了Content-Type HTTP标头缺少字符集属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在安全检查期间,它报告说js和css文件缺少"Content-Type HTTP标头缺少字符集属性".

During security check, its reported that "The Content-Type HTTP header is missing charset attribute" is missing for js and css file.

请检查以下屏幕截图:

在我添加字符集之前,我的HTML如下所示

My HTML Was look like below before i have added the charset

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="/backend/web/assets/3faf0a44/jquery.js"></script>
    </head>
</html>

然后我在

<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8">
        <script type="text/javascript" src="/backend/web/assets/3faf0a44/jquery.js" charset="UTF-8"></script>
    </head>
</html>

在响应标题中未添加静态字符集,请检查以下屏幕截图:

Still Charset is not added in Response Header, Please check below screenshot:

那我该怎么做,以便我的Content-Type标头更改为以下内容:

So what should i do so my Content-Type header changed to below:

推荐答案

让我尝试回答,您可以通过编辑apache2.conf(对于Debian之类的OS)或httpd.conf(CentOS之类的OS( es))并添加以下几行:

Let me try to answer, you can do that by editing apache2.conf (for Debian like OS(es) ) or httpd.conf ( CentOS like OS(es) ) and add following lines:

#Set the correct Char set so don't need to set it per page.
AddDefaultCharset utf-8
#for css, js, etc.
AddCharset utf-8 .htm .html .js .css

来源:

  • https://httpd.apache.org/docs/2.4/mod/core.html#adddefaultcharset
  • https://httpd.apache.org/docs/2.4/mod/mod_mime.html#addcharset

这篇关于Content-Type HTTP标头缺少字符集属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-01 06:08