Firefox vs UTF-8

I had an unusual issue while I was updating the MSDNAA site of our university: the pages rendered correctly when I opened them from my own computer, but not from the server. Almost all browsers displayed them perfectly, except Firefox that showed ugly characters instead of the special Hungarian accented chars.

I checked the files, all of them were saved correctly in UTF-8 with the byte-order-mark in the beginning – which was not hard to recognize thanks to Firefox that rendered them on the page: 

Because the site now consists of brand new HTML5 pages, all page contains the <meta charset="utf-8" /> line, but I also added the classic Content-Type line for sure – in vain.

After the quick checks, back to Rule #1: When in doubt, start Fiddler! Fiddler showed me the following header in the response:

Content-Type: text/html; charset=iso-8859-1

This was the moment when I understood why the old files were all saved in ISO-8859-1: because this header is forced by the webserver! And the setting in the header overwrites the setting in the page – at least in Firefox now.

Because the site runs on Apache in a shared hosting environment without ASP.NET, PHP or admin access, server side code was not an option to overwrite the header. None the less the final solution became quite simple. I just added this single line to the .htaccess file in the root of the site:

AddDefaultCharset UTF-8

The settings in the root are applied to the subfolders as well.


Technorati-címkék: ,,

One thought on “Firefox vs UTF-8

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s