28

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!

Cris
  • 4,004
  • 16
  • 50
  • 74

3 Answers3

43

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)

Community
  • 1
  • 1
NXT
  • 1,981
  • 1
  • 24
  • 30
  • I know it should simply work but my HTTP Header still just respond with Content-Type text/html. I don't want to use a tag in my document to declare the character encoding. I use Apache 2.4. – Tomkay Jun 27 '13 at 10:50
  • 1
    @Tomkay make sure the server process .htaccess directives and the file is located in the proper directory – NXT Jun 28 '13 at 08:59
3

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

Remy Lebeau
  • 555,201
  • 31
  • 458
  • 770
Luuk
  • 12,245
  • 5
  • 22
  • 33
  • UTF-8 seems to be the default for IIS (http://technet.microsoft.com/en-us/library/cc771836%28v=ws.10%29.aspx) – Luuk Dec 27 '14 at 14:09
1

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.

Jon Hanna
  • 110,372
  • 10
  • 146
  • 251