1

I have recently designed a website that contains German and Dutch characters and I would like the page to use character encoding utf-8.

I have added the xml declaration:

<?xml version="1.0" encoding="UTF-8"?>

and the meta tag:

<meta http-equiv="content-type" content="text/html; charset=UTF-8" />

When I viewed the website on-line, the special characters found in the German text were not displaying correctly. When I tried validating the page with the w3c validator, I got the following warning:

The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the XML declaration (utf-8). I will use the value from the HTTP header (iso-8859-1).

Is this a server issue? It's just that I have uploaded the same files to a different server of mine and the pages display correctly there using utf-8.

Any help or advice regarding how I would go about getting the page to encode as utf-8 would be greatly appreciated.

I'm stumped!


Thanks to jason, I found a file named mod_mime-defaults.conf

this file contains the following:

# AddDefaultCharset UTF-8
AddDefaultCharset ISO-8859-1

If I remove the # from before AddDefaultCharset UTF-8, do you think this will help? Or maybe add a # before AddDefaultCharset ISO-8859-1.

I tried editing this file, but I don't think I have permission. Hmmm...?

ade123
  • 2,773
  • 8
  • 29
  • 32
  • You need to do both, comment out the ISO line and remove the # on the UTF-8 line. The # character comments out that line, but you will need permission to edit this file. "AddDefaultCharset ISO-8859-1" means all files served from your web server will default to ISO-8859-1. – Jason Jan 05 '11 at 06:05
  • ok, so it sounds like I definitely need to alter the file named: mod_mime-defaults.conf, so that the AddDefaultCharset ISO-8859-1 is commented out and the AddDefaultCharset UTF-8 is not. I don't seem to have permission to alter this file though. Guess I'll have to try and get the server owner to have a go at this. Hmmm... – ade123 Jan 05 '11 at 20:42
  • Depending on server permissions for that user, you may be able to upload an .htaccess file to the website root with the required `AddDefaultCharset utf-8` rule. This will override the global server setting. – Dave Everitt Apr 02 '13 at 11:11

3 Answers3

3

This could be a server issue.

If you are using Apache check the Apache config file usually located here /etc/httpd/conf/httpd.conf on a *nix server, for the value of AddDefaultCharset.

This setting specifies the default for all content served. If it is commented out, that means it will rely on the browser's, or META settings to determine the Charset.

Jason
  • 393
  • 1
  • 5
  • 18
  • encoding in meta tag should be equal to the server encoding, e.g `` and `AddDefaultCharset utf-8`. `utf-8` is hyphenated – mountpoint Apr 12 '15 at 20:13
0

The HTML meta tag is not the same as the HTTP response header. You need to set the character encoding in the HTTP response header. As per your question history you're using PHP -or are at least familiar with it-, so here's a PHP targeted example of how to do it.

Put the following line in the PHP file before you echo any character.

header('Content-Type: text/html;charset=UTF-8');

See also:


Unrelated to the problem: you shouldn't put a XML declaration on a HTML page. This is recipe for other sort of trouble.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555
  • Hmmm... I'm not using any php files here, just .html files. If I remove the xml declaration, I just get the same warning from w3c validator, but just saying "The character encoding specified in the HTTP header (iso-8859-1) is different from the value in the meta declaration (utf-8). I will use the value from the HTTP header (iso-8859-1)". I really need to change the http header to utf-8 if this is possible or make it so that the meta declaration has precedence over the http header. I'm really not too sure what I'm doing here? – ade123 Jan 05 '11 at 03:43
  • @ade123 - as outlined above. It definately sounds like your Apache server setting for AddDefaultCharset, because that setting is designed to override your META settings. – Jason Jan 05 '11 at 06:12
  • Then you need to configure it in the webserver itself, indeed. Click the 2nd "See also" link to learn more about the difference between the HTTP response header and the HTML meta tag. – BalusC Jan 05 '11 at 10:59
  • @BalusC can you help with this issue http://stackoverflow.com/questions/20297160/joomla-utf-8-encoding-fails-on-opening-the-mail – R R Nov 30 '13 at 06:58
-1

I changed charset=UTF-8 to charset=iso-8859-1, and the warning went away.