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

Cris picture Cris · Nov 1, 2011 · Viewed 47.6k times · Source

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!

Answer

NXT picture NXT · Jan 15, 2013

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)