Setting default encoding in .htaccess

March 29th, 2010 by Alex Leave a reply »

When you sometimes have to transfer a website from one hosting to another (you’ll definitely need to eventually), you may experience that the files load in another encoding, thus you didn’t edit or change the files anyway.

This may be overridden via simple .htaccess directive:

AddDefaultCharset UTF-8

Going further, you can try some complex directives for certain file types:

AddCharset UTF-8 .html
AddType 'text/plain; charset=UTF-8' txt

Or using FilesMatch:

<FilesMatch "\.(htm|html|css|js)$">
AddDefaultCharset UTF-8

Or set the encoding for a particular file:

<Files "index.html">
AddCharset UTF-8 .html

This page can be found by searching for:

htaccess default charsetdefault charset htaccess


  1. kim s b says:

    잘쓰겠습니다 감사합니다

  2. Thank you very much for sharing. It helped me solve my encoding problem