Author Topic: Apache encoding  (Read 6212 times)

Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
Apache encoding
« on: November 20, 2009, 07:25:31 PM »
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:

Code: [Select]
AddDefaultCharset utf-8
AddCharset utf-8 .txt .html .htm .php

Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
Re: Apache encoding
« Reply #1 on: November 20, 2009, 07:27:19 PM »
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′);


Offline admin

  • Administrator
  • Sr. Member
  • *****
  • Posts: 296
    • View Profile
Re: Apache encoding
« Reply #2 on: November 20, 2009, 07:30:32 PM »
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.