By using this site you agree to the use of cookies.

Learn more

Share via:

Apache: Changing Default Character Set For Static HTML Files

How to add a default character set to be used for text and HTML files delivered with the apache HTTP server.

Edited: 2017-09-08 19:10

If static files are showing up incorrectly when requested in a browser, you can simply set a default character set to be used in Apache's configuration files. Typically you would set the character set to UTF-8.

The preferred way to do this, is to edit the main configuration file of apache. In Linux, this will often be located at /etc/apache2/apache2.conf. Adding the AddDefaultCharset directive somewhere in this file will solve the problem. You may wish to set this at UTF-8, to support a broad set of characters.

Note. This will add support the Danish letters Æ, Ø and Å.

Simply add the below somewhere in the apache2.conf file:

AddDefaultCharset utf-8

This will only work for text/plain or text/html content types, and should also overwrite the character set declared in meta elements in the HTML.

Alternatively, if you want to control things on a per-site basis, you can also add it to your v-host file'(s) instead.

The name and location of the main confiuration may depend on which Linux distribution you are using, how you installed Apache. And God knows what. If you can not find apache2.conf, you should look up the documentation for your distribution. It is also common that the main configuration file is called httpd.conf, located at /etc/httpd/conf/httpd.conf.