How do I set Character Encoding to UTF-8 for default.html?

前端 未结 5 1509
庸人自扰
庸人自扰 2020-12-01 13:05

I spent the last few hours getting my website to validate HTML 4.01 Strict and I actually have succeeded in that but there is still one warning which I can\'t get rid of. Th

相关标签:
5条回答
  • 2020-12-01 13:09

    The server is clearly marking the document as ISO-8859-1 in the HTTP headers. Try saving default.html using UTF-8 encoding with a proper editor.

    0 讨论(0)
  • 2020-12-01 13:18

    Can you remove AddDefaultCharset from .htaccess and check the encoding? I saved the HTML source of your webpage and opened it. Encoding was detected as UTF-8. However, on viewing the same webpage served by your webserver, the encoding is ISO-8859-1. That is why I suggest removal of the former redundant rule.

    0 讨论(0)
  • 2020-12-01 13:19

    You need to replace the HTTP-level header.

    This should work:

    <?php 
     header('Content-type: text/html; charset=utf-8'); 
    ?>
    

    Note that the above must be the FIRST thing in your file. No exceptions. See http://us2.php.net/manual/en/function.header.php

    For general info on how to change the character set header in different web stacks, see http://www.w3.org/International/O-HTTP-charset

    Larry

    0 讨论(0)
  • 2020-12-01 13:26

    Okay, I have come up with a partial solution to my problem. As it was only the default.html file which was causing the warning I assumed that the server was doing something special to it because of its name. So I made a new file called home.html with the same contents as the default.html file and pointed the .htaccess file to the new file (see line 3 below).

    # Use PHP5 as default
    AddHandler application/x-httpd-php5 .php
    DirectoryIndex home.html
    AddDefaultCharset UTF-8
    

    This fixed the problem and all files are now recognised as UTF-8. I'm still not sure what the server was doing to the default.html file or where the settings concerning that are but as my problem is gone I will forget about that.

    0 讨论(0)
  • 2020-12-01 13:34

    include this in your code:

    <meta charset="utf-8" />

    0 讨论(0)
提交回复
热议问题