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

character encodingcontent-typehttp-headersoptimization

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!

Best Answer

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)