server-side includes and character encoding

和自甴很熟 提交于 2019-12-23 13:24:09

问题


I created a static website in which each page has the following structure:

  1. Common stuff like header, menu, etc.
  2. Page specific stuff in main content div
  3. Footer

In this website, all the common content is duplicated in each page. In order to improve the maintainability I refactored the pages to use server-side includes (SSI) so that the common content is not duplicated. The structure of each page is now

  1. SSI for Common stuff like header, menu, etc.
  2. Page specific stuff in main content div
  3. SSI for footer

In the refactored site, for some reason the French characters no longer display properly in the page-specific content area, though they display fine in the content included via SSIs.

The included header specifies the character set as:

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

If I open one of the main content pages in a browser it tells me that the character encoding is ISO-8859-1. I've tried adding a .htaccess file to the folder with the lines

AddDefaultCharset UTF-8
AddCharset UTF-8 .shtml
AddCharset UTF-8 .html

But still those pesky French accents aren't displaying properly on the version of the site that uses SSIs.


回答1:


You are serving your pages as UTF-8, which is good, but at least some of the page is being dragged in from files which are not actually saved as UTF-8. SSI just throws the raw bytes in, it doesn't attempt to recode the includes so that their charsets match the file they're being included into.

You need to go through all your html and include files in a text editor and make sure each one is saved as UTF-8.

As John mentioned, you can avoid encoding issues by using character references for all non-ASCII characters, but it's a tremendous pain.




回答2:


Your HTML document is using UTF-8 encoding, try these character codes for your accented letters: http://www.tony-franks.co.uk/UTF-8.htm




回答3:


I had the same problem as you and finally found a solution that fixed it.

UTF8 makes an extra line on my site

Save all your files as UTF-8 without BOM (http://en.wikipedia.org/wiki/Byte_order_mark).



来源:https://stackoverflow.com/questions/539661/server-side-includes-and-character-encoding

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!