HTTP headers
When a server sends a document to a user agent (such as a browser), it also sends information about the document in a portion of the document called the HTTP header. A typical HTTP header looks like this:
HTTP/1.x 200 OK
Date: Mon, 14 Nov 2005 19:45:33 GMT
Server: Apache/2.0.46 (Red Hat)
Accept-Ranges: bytes
Connection: close
Transfer-Encoding: chunkedContent-Type: text/html; charset=UTF-8
Notice that one of the bits of information that the server sends
along is the Content-Type
of the
document using a MIME type label. For example, HTML documents are
always delivered as type text/html
.
(The MIME types for XHTML documents aren’t as straightforward, as
discussed in the sidebar, “Serving XHTML.”) The Content-Type
entry may also contain the
character encoding of the document using the charset
parameter, as shown in the
example.
The method for setting up a server with your preferred character encoding varies with different server software, so it is best to consult the server administrator for assistance. For Apache servers , the default character encoding may be set for all documents with the .html extension by adding this line to the .htaccess file.
AddType 'text/html; charset=UTF-8' html
The advantages to setting character encodings in HTTP headers are that the information is easily accessible to user agents and the header information has the highest priority in case of conflict. On the downside, it is not always easy for authors to access the server settings, and it is possible ...
Get Web Design in a Nutshell, 3rd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.