I’ve been currently working on a application that should render charset ISO-8859-1 to the browser. So I’ve added a following meta tag to HTML document header.
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
For some reason when rendering the page, it always makes some characters broken or not been recognised. I’ve spend a good few hours to debug this situation thought it was due to some issue with application itself how it handles encoding.
Thanks to built-in browser “Inspect Element” tool, I’ve managed to crack down the root issue. It was causing this issue due to Response ContentType set to use charset UTF-8.
Content-Type:text/html; charset=utf-8
Application wasn’t setting ContentType charset in Response, Then where did this charset came from ?. HTML header meta tag wasn’t taking a effect in this case. It has overridden by Response ContentType charset.
-This is the time Apache took my attention.
It turned out that Apache was automatically sets AddDefaultCharset config directive to be UTF-8. It was automatically added to /etc/httpd/conf/httpd.conf by Default Installation.
AddDefaultCharset UTF-8
I’ve commented out AddDefaultCharset directive form Apache config and reloaded Apache, it worked as expected.
I guess if you wanted to control encoding by application level then you should AddDefaultCharset Off or remove it from Apache config.
Hope this helps to solve unexpected encoding issues due to Apache config.