News:

To still receiving newsletters from us please subscribe to our Newsletters:
http://tech.groups.yahoo.com/group/developers-Heaven/

Main Menu

Apache encoding

Started by admin, November 20, 2009, 12:25:31 PM

Previous topic - Next topic

admin

Some hosting providers have problems with encodings. Default they serve HTML documents as ISO-8859-1 encoding (via the HTTP Content-Type header). That is so last century. a simple solution that works for me. Create a file named .htaccess (the beginning dot is necessary, and renders the file invisible on UNIX/Linux systems) with the following content:

AddDefaultCharset utf-8
AddCharset utf-8 .txt .html .htm .php

admin

If you want to set header of php files without .htaccess you can use:

header('Content-Type: text/html; charset=utf-8′);
or
header('Content-Type: text/html; charset=iso-8859-1′);


admin

There is a better way to do that: encode the charset information in the filename, and apache will output the proper encoding header based on that. This is possible thanks to the AddCharset lines in the conf file, such as the line below:

conf/httpd.conf:AddCharset UTF-8       .utf8

So if you have a file whose names ends in .html.utf8, apache will serve the page as if it is encoded in UTF-8 and will dump the proper character-encoding directive in the header accordingly.