// you’re reading...

Tips N Tricks

Display Microsoft Word’s Special Characters through Apache

Recently, I carried out a Linux server upgrade for a client where I did a clean install of the latest operating system/distribution. Since it was a clean install I had to backup and note down the earlier configuration (of mail server, web server, database) and redo those changes. Mostly I preferred not to simply overwrite with the backed up configuration files. I rather documented and edited the configuration manually.

It all seemed to have gone smoothly and the new server has been up and running. But one not-so-fine day, the client started complaining that some HTML pages are not displaying properly. These were showing question marks (?) and some other weird characters. I figured out that these HTML pages were generated using Microsoft Word and had those special characters (closing quotes, double hyphens etc.). I discussed with the client that this could be a web browser problem because it is not able to use the correct character set.But the client insisted that such pages used to display properly earlier, before the upgrade.  This meant I have missed redoing some configuration. The obvious suspect was at Apache web server side. After all it is Apache which is serving these web pages to the browser. Hence, if the culprit is not the web browser then it better be the web server. After parsing through the Apache’s configuration file I spotted a comment against a directive (or configuration option) called AddDefaultCharset which said:

# Specify a default charset for all content served; this enables
# interpretation of all content as UTF-8 by default.  To use the
# default browser choice (ISO-8859-1), or to allow the META tags
# in HTML content to override this choice, comment out this
# directive:

I followed it and commented out the directive and voila it worked!

To sum up, if HTML files served by an Apache web server  are not displaying special characters properly in a web browser (IE, Firefox etc.), the solution is:

  • Open the Apache’s configuration file named httpd.conf (found in the directory /etc/httpd/conf for RedHat based Linux distributions) in a text editor
  • Comment out, by prefixing a hash (#), the line which says “AddDefaultCharset UTF-8″ such that it looks as follows:
    # AddDefaultCharset UTF-8
  • Save the file and reload/restart Apache server. For RedHat based distributions you can do this via “service httpd reload”
GD Star Rating
loading...
GD Star Rating
loading...
Display Microsoft Word's Special Characters through Apache, 9.0 out of 10 based on 2 ratings
  • Share/Bookmark

Email This Post Email This Post Print This Post Print This Post Post A Comment Post A Comment Tweet your comments/question to me @shekharg

Discussion

4 comments for “Display Microsoft Word’s Special Characters through Apache”

  1. It’s a nice experience!

    But can u guide me why Microsoft word’s special character are creating such type of problem in Apache server?

    GD Star Rating
    loading...

    Posted by pankaj | March 25, 2009, 11:44 am
  2. why Microsoft word’s special character are creating such type of problem in Apache server?

    The web browser uses a META tag, written in the web page, to choose the character set (http://en.wikipedia.org/wiki/Character_encoding) to display the characters or content in the web page.

    For example, the following is the META tag found in a HTML file (web page) generated by MS Word:

    With this tag the web page instructs the web browser to use windows-1252 to display the page. With this character set, the browser can display all the, so called, special characters properly.

    Apache (atleast the default configuration) tells the browser to use UTF-8 (http://en.wikipedia.org/wiki/UTF-8) as the character set. The browser respects the web server more than the web page :-) Commenting out this line tells the web browser to use whatever character set mentioned in the META tag of the page.

    GD Star Rating
    loading...

    Posted by Shekhar | March 25, 2009, 12:59 pm
  3. Very helpful.
    You saved many hours of me.
    Thanks.

    GD Star Rating
    loading...

    Posted by sanjay Katiyar | April 13, 2009, 11:05 am
  4. Yep it also took me lots of “time, energy, brain” = googling ;-)

    GD Star Rating
    loading...

    Posted by Shekhar | April 13, 2009, 12:39 pm

Post a comment

shekharg: RT @aseemsood: Good news today - Delhi Metro Link between C-Sec and Qutub Minar opens today. http://bit.ly/bCXTbw
16 hours ago, comment
shekharg: I disagree, Twidroyd is the best RT @TweetDeck: New Android TweetDeck Beta is so great that we've skipped v6 & gone straight to 7!
11:05 AM Sep 02, 2010, comment
shekharg: Check out this UI http://nyti.ms/cr0Wcg
10:38 AM Sep 02, 2010, comment
shekharg: Let's declare Gurgaon a part of Pakistan till #CWG2010, to keep away the visitors from seeing the condition of roads here
9:34 AM Sep 02, 2010, comment
shekharg: RT @TechCrunch: Google Making Extraordinary Counteroffers To Stop Flow Of Employees To Facebook - http://tcrn.ch/bpdbYT by @arrington
2:18 PM Sep 01, 2010, comment