Change the default Apache character set

By default, Red Hat Enterprise Linux 4 sets the default character set in Apache to UTF-8. Your specific web application may need for the character set to be set to a different value, and the change can be made fairly easily. Here's an example where the character set is changed to ISO-8859-1:

First, adjust the AddDefaultCharset directive in /etc/httpd/conf/httpd.conf:

#AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1

Then, reload Apache and check your headers:

# /etc/init.d/httpd reload
# curl -I localhost
HTTP/1.1 403 Forbidden
Date: Thu, 08 Nov 2007 22:18:14 GMT
Server: Apache/2.0.52 (Red Hat)
Accept-Ranges: bytes
Content-Length: 3985
Connection: close
Content-Type: text/html; charset=ISO-8859-1

This was tested on Red Hat Enterprise Linux 4 Update 5

Printed from: http://rackerhacker.com/2007/11/15/change-the-default-apache-character-set/ .
© Major Hayden 2012.

2 Comments   »

  • thornibr says:

    this was done because of the issues with MySQL within RHEL4 prior to that update.

    See:

    https://wiki.intra.rackspace.com/kwiki/index.cgi?MySQLhttpCharacterConfig

    Basically MySQLs global.character_set_results was ISO-8859-1 whereas httpd was UTF-8

    RHEL3, 2.1 and whatever else is ISO-8859-1 for httpd.

    Basically the website page encoding (if not set, AddDefaultCharset in httpd.conf) MUST match character_set_results for MySQL!!!!

  • hi, i have a situation;
    in my server:
    export | grep LANG
    response is:
    declare -x LANG="en_US.UTF-8

    in httpd.conf:
    #AddDefaultCharset UTF-8
    (so there is no charset definition...)

    i am using Plesk over Centos 5 (2.6.18-194.32.1.el5) i386, but one of my web site debug says:

    "Server charset Encoding: You must set a correct charset encoding in your locale definition in the form: en_us.UTF-8. Please refer to setlocale man page. Detected locale: C (using UTF-8) "

    so here is the question:

    can i edit/change only one vhosts httpd.conf's Charset?...

RSS feed for comments on this post

Leave a Reply

 

  • Welcome! I started this blog as a way to give back to all of the other system administrators who have taught me something in the past. Writing these posts brings me a lot of enjoyment and I hope you find the information useful. If you spot something that's incorrect or confusing, please write a comment and let me know. Drop me a line if there's something you want to know more about and I'll do my best to write a post on the topic.
    -- Major Hayden

    Flattr this