How to specify the character set in the HTTP Content-Type response header?

48,219

Solution 1

Apache: add to your .htaccess file in root directory:

AddDefaultCharset UTF-8

It will modify the header from this:

Content-Type text/html

...to this:

Content-Type text/html; charset=UTF-8


nginx [doc] [serverfault Q]

server {
   # other server config...
   charset utf-8;
}

add charset utf-8; to server block (and reload nginx config)

Solution 2

When i added this, my response header looked like this:

HTTP/1.1 200 OK
Content-Type: text/html,text/html;charset='UTF-8'
Vary: Accept-Encoding
Server: Microsoft-IIS/7.5

Solution 3

With Apache, you use http://httpd.apache.org/docs/2.2/mod/core.html#adddefaultcharset

With IIS you edit the MIME type for the filetype in the list of files.

With most server-side technologies like PHP or ASP.NET there's a method or property provided by that technology. For example in ASP.NET you can set it in config, page, or page code-behind.

Share:
48,219
Cris
Author by

Cris

Updated on December 31, 2020

Comments

  • Cris
    Cris over 3 years

    I had my site tested with the Page Speed app from Google and one of the suggestions was to specify the character set in the HTTP Content-Type response header claiming it was better than just in a meta tag.

    Here's what I understand I need to write: Content-Type: text/html; charset=UTF-8

    ..but where exactly should I put this? I'm on a shared server.

    Thank you!