I've got the following in the .htaccess
located in the root directory of website https://klipspringer.avadeaux.net/:
AddDefaultCharset UTF-8
AddCharset UTF-8 .js
AddCharset UTF-8 .html
AddCharset UTF-8 .java
AddCharset UTF-8 .c
AddCharset UTF-8 .css
This works fine for most code files that can be viewed in the browser. For instance, when viewing sendcmd.js in Chrome, the “–” character in “2014–2021” is correctly displayed:
But the UTF-8 directive doesn't seem to work for .java
files. For instance, in TrackChain.java, Chrome displays the UTF-8 bytes of the “–” character as three characters:
Any ideas why, or what can be done about it?
Safari has the same problem as Chrome (while Firefox doesn't want to show Java files at all, but prompts me for a downloading destination).
(Bonus question: Is there any way to set the charset for files that don't contain a ‘.
’, like Makefile?)
UPDATE: The following worked for viewing Java and and Makefile in UTF-8:
<FilesMatch "\.java$">
Header set Content-Type "text/x-java-source; charset=UTF-8"
</FilesMatch>
<FilesMatch "^[Mm]akefile$">
Header set Content-Type "text/plain; charset=UTF-8"
</FilesMatch>
Why the AddCharset UTF-8 .java
line has no effect is however still a mystery to me.