0

My website has pages and other content with UTF-8 encoding. For HTML, setting the encoding in a meta tag is no problem. However, I also have raw text files with UTF-8 encoding that aren't displayed correctly, such as appearing as ×. I've considered adding a byte-order mark at the start of such files, but I'd prefer not to since they aren't always well supported. I followed the instructions in this other question, but it had no effect. This is the HTTP response header:

HTTP/1.1 200 OK
Date: Sat, 12 Aug 2017 15:41:04 GMT
Server: Apache/2.4.10 (Debian)
Last-Modified: Wed, 09 Aug 2017 19:24:33 GMT
ETag: "c04c-5565707a34966"
Accept-Ranges: bytes
Content-Length: 49228
Keep-Alive: timeout=5, max=100
Connection: Keep-Alive

I was hoping to see Content-Type: text/plain; charset=utf-8. How can I get reliable UTF-8 encoding for these URIs?

2

Content-Type is not sent for 304 Modified responses because there is no content body for such a response.

Look at the 200 response type and you should see this. Use Ctrl + F5 to force a refresh and a 200 response rather than revalidating the cached response with a 304 response.

You then updated your question to include a 200 response, but I would expect that always to have a Content-Type: text/plain header or equivalent (even if the character set is not included) but that is not in your example, so not sure you have all the details in that?

Regardless, the correct way to set this is to add the following to your apache config:

#Set the correct Char set so don't need to set it per page.
AddDefaultCharset utf-8
#for css, js, etc.
AddCharset utf-8 .htm .html .js .css

The first (AddDefaultCharset) will set the charset for text/plain and text/html resources.

The second (AddCharset) requires mom_mime and will set the charset for other types based on file extension. Javascript files are sent with content type of application/javascript and CSS files are sent with content type of text/css so are not picked up by the AddDefaultCharset setting. The .htm and .html files don't really need to be in this as will be picked up by default but no harm being explicit.

  • I've updated the question with the 200 response – Brent Aug 12 '17 at 15:42
  • 1
    Not sure you did that right, but updated the answer anyway. – Barry Pollard Aug 13 '17 at 11:20
  • Thank you for bearing with me. I've checked sudo apache2ctl -M and mime_module (shared) appears and I've added the AddCharset directive. I'm still not seeing the response header for the .yml linked in the OP. Here's my /etc/apache2/apache2.conf pastebin.com/hXJhmTSA . I believe that is the right file based on running apache2ctl -V as described here: serverfault.com/questions/12968/… . Do I need to also indicate somehow that .yml is text/plain? – Brent Aug 13 '17 at 16:02
  • I also needed to add AddType text/plain .yml, and it works now. – Brent Aug 13 '17 at 16:08
  • You could have also added it to the other line: AddCharset utf-8 .htm .html .js .css .yml – Barry Pollard Aug 13 '17 at 16:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.