Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change Charset Response Header for Apache Indexes

I'm trying to set up windex on my local apache server for changing the auto-generated file indexes; some of my files and folders have utf-8 characters such as ».

This shouldn't be a problem, as the html header has the charset set to utf-8. The php files have been encoded in utf-8. I've even set 'AddDefaultCharset' to off 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 is causing this, and how do I stop it?

like image 782
elstgav Avatar asked Mar 06 '11 05:03

elstgav


2 Answers

Turns out that Apache has a separate setting for encoding the indexes it generates. You can set the charset for an index by adding this line to an .htaccess file, placed in the directory where your index will be generated:

IndexOptions Charset=UTF-8

This fixed it for me!

like image 121
elstgav Avatar answered Oct 13 '22 14:10

elstgav


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

AddDefaultCharset utf-8

AddCharset is to define the character set for any given file extension.

In .htaccess or httpd.conf you can add:

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

In PHP (before any page content is output):

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

If you HAVE to use the HTML meta tag (cannot edit config or htaccess) it must be the first thing that follows the <head>
Reference: Best Practice: Get your HEAD in order

<head><meta http-equiv="content-type" content="text/html; charset=UTF-8">
like image 32
Misunderstood Avatar answered Oct 13 '22 13:10

Misunderstood