Wrong default encoding on the Apache webserver

Published on 2007-08-22.

This is a mini tutorial in solving problems with the Apache webserver encoding specifications.

By default the Apache directive AddDefaultCharset is set to Off which means that the encoding of the webpage is set by the HTML META tags.

Normally you set the default encoding with HTML in the META tags like this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

Or with HTML5 like this:

<meta charset="UTF-8">

A problem can occur if your Apache webserver or PHP installation is not configured properly in which the Apache webserver still uses the ISO-8859-1 encoding rather than UTF-8 or something else.

To fix this you can either change the directive AddDefaultCharset to UTF-8 in your httpd.conf configuration file like this:

AddDefaultCharset UTF-8

In which case the default encoding of Apache will be UTF-8.

You can also change the directive AddDefaultCharset to OFF in your httpd.conf configuration file:

AddDefaultCharset OFF

And then handle all encoding from HTML. Make sure that the mimetype and charset directives of PHP is set correctly in php.ini, if you're using PHP.

The directive:

default_mimetype = "text/html"
default_charset = "iso-8859-1"

Should be changed to:

default_mimetype = ""
default_charset = ""

From this point forward your pages should be rendered as whatever encoding you specify in the META tag.

Another options is to add this to your .htaccess in case you have access to it:

IndexOptions +Charset=UTF-8

This will also set the default encoding of Apache to UTF-8.