add charset to http header using htaccess

#1
Hi I been trying to add charset= utf-8 using htaccess.
It works on my php files and if I add AddDefaultCharset UTF-8 that I read is supported by Litespeed I get for the php files this http header:
Content-Type => text/html; charset=UTF-8
However it does not work on .css or .js files, I get this as header only:
Content-Type => text/css

I spoked to the host and he think its due to the gzipping of the files, but also the static content in the php files is being gzipped.

Should this work on .css files or can it be done in another way?

I am preparing my web for mobile devices and an error I get from w3s mobile checker is that my .css file does not have charset utf-8 in the http header, so I would like this fixed.

Thanks in advance
Helen
 
Last edited:

NiteWave

Administrator
#2
I did simple tests(phpinfo.php) on apache and lsws, lsws is compatible with apache in this regards.

refer apache document:
http://httpd.apache.org/docs/2.0/mod/core.html#adddefaultcharset
AddDefaultCharset On|Off|charset
works.

please note in the document:
"This directive specifies a default value for the media type charset parameter (the name of a character encoding) to be added to a response if and only if the response's content-type is either text/plain or text/html. "

so AddDefaultCharset only affect text/plain or text/html, not affect text/css
 
#3
I did simple tests(phpinfo.php) on apache and lsws, lsws is compatible with apache in this regards.

refer apache document:
http://httpd.apache.org/docs/2.0/mod/core.html#adddefaultcharset
AddDefaultCharset On|Off|charset
works.

please note in the document:
"This directive specifies a default value for the media type charset parameter (the name of a character encoding) to be added to a response if and only if the response's content-type is either text/plain or text/html. "

so AddDefaultCharset only affect text/plain or text/html, not affect text/css
Thanks, I tried all in this apache link:
http://www.askapache.com/htaccess/setting-charset-in-htaccess.html
and non did work.
So how can I set charset for a .css files?
Would any of these work?
<filesMatch "\.(htm|html|css|js)$">
ForceType 'text/html; charset=UTF-8'
</filesMatch>

<filesMatch "\.(htm|html|css|js)$">
AddDefaultCharset UTF-8
</filesMatch>

I get this error at w3s mobilechecker:
One of the resources required to render the page (most likely a CSS style sheet) does not declare its encoding as UTF-8 in
an HTTP Content-Type header. Check that its content is properly encoded, and consider declaring its encoding at the HTTP level.

So can it be done?
Regards,
Helen
 
#4
I also tried this:
AddType 'text/css; charset=UTF-8' .css
and it does not work
Many says this works in apache:
AddCharset utf-8 .css .js
But I read AddCharset is not supported in LiteSpeed, or at least was not in the list I saw as supported
 

mistwang

LiteSpeed Staff
#5
upcoming 4.1.12 release will support

AddType 'text/css; charset=UTF-8' .css

and
AddDefaultCharset UTF-8

will work for context type starting with "text/", so, it can cover .css, but not .js.
 
#6
upcoming 4.1.12 release will support

AddType 'text/css; charset=UTF-8' .css

and
AddDefaultCharset UTF-8

will work for context type starting with "text/", so, it can cover .css, but not .js.
Hi again,
My host have now upgraded to 4.1.12,
I tried both of previous and none worked for the ,css file.
Is it supported by 4.1.12?
 
#7
Does the 4.1.12 release support
AddType 'text/css; charset=UTF-8' .css
and
AddDefaultCharset UTF-8 as said before in this thread?
Or am I or the host doing something wrong?
Would appreciate an answer, thanks.
 
Top