Change Charset response header for Apache indexes

I am trying to configure windex on a local Apache server to change the indexes of automatically generated files; some of my files and folders have utf-8 characters, such as ".

This should not be a problem, as the html header has a character set set to utf-8 . Php files were encoded in utf-8 . I even installed ' AddDefaultCharset ' in my httpd.conf for the Apache server, but when I try to load any page, I get " Content-Type:text/html;charset=ISO-8859-1 " in the response header.

What causes it and how to stop it?

+4
source share
3 answers

It turns out that Apache has a separate parameter for encoding the indexes it generates. You can set the encoding for the index by adding this line to the .htaccess file placed in the directory in which your index will be created:

 IndexOptions Charset=UTF-8 

It fixed it for me!

+10
source

AddDefaultCharset is used when the response header content type is text / plain or text / html
In .htaccess or httpd.conf you can add:

 AddDefaultCharset utf-8 

AddCharset is a character set definition for any given file extension.

In .htaccess or httpd.conf you can add:

 AddCharset utf-8 .html .css .php .txt .js 

In PHP (before outputting any page content):

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

If you use the HTML meta tag (cannot edit config or htaccess), this should be the first thing that follows the <head>
Link: Best Practice: Get your HEAD in order

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

For html
Put the following <head> </head> tags:

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

For xhtml
Put the following <head> </head> tags:

 <meta http-equiv="content-type" content="application/xhtml+xml; charset=UTF-8"/> 

Start your php files with:

 <?php echo "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" ?> 
-1
source

Source: https://habr.com/ru/post/1342486/


All Articles