Apache2 changing charset using .htaccess

If you do not wish to change character encoding for the entire server, but only one site (or only one directory) then this is possible to do using .htaccess.

AddDefaultCharset UTF-8

If you only wish to do this to php or htm files (and not all files)

<FilesMatch "\.(htm|php)$">
AddDefaultCharset UTF-8
</FilesMatch>

If you wish to modify the mime-type as well as the encoding (on html files in this example)

AddType 'text/html; charset=UTF-8' html

Tags: , , , , , , , ,

3 Responses to “Apache2 changing charset using .htaccess”

  1. [...] Make sure the right encoding is used to present the file (meta charset) / .htaccess or similar [...]

  2. [...] get a html page to display UTF-8 encoded text correctly (without setting a default charset) simply add the following to the head of the html page. <meta [...]

  3. [...] Setting a default charset using .htaccess is a simple thing to do [...]

Leave a Reply