服务器端包含和字符编码 [英] server-side includes and character encoding

查看:162
本文介绍了服务器端包含和字符编码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了此静态网站,其中每个网页的结构如下:





  • li> Footer

    在上面链接的网站中,所有常见的内容都在每个页面重复。为了提高可维护性,我重构了页面以使用服务器端包含(SSI),使得公共部分不重复。每个网页的结构现在是


    1. SSI适用于标题,菜单等常见内容。

    2. 主要内容div中的特定页面

    3. 页脚的SSI

    我上传了重构网站到此地址,并且您可以看到它没有完全解决。由于某些原因,法语字符在页面特定内容区域中不再正确显示,尽管它们在通过SSI包括的内容中显示良好。



    包含的标题指定字符集:

      meta http-equiv =Content-Typecontent =text / html; charset = UTF-8/> 

    如果我在浏览器中打开一个主要内容页面,它告诉我,字符编码是ISO -8859-1。我试过添加一个.htaccess文件到文件夹

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

    但这些讨厌的法语口音



    $ b

    干杯,
    Don

    解决方案

    您以UTF-8的形式提供页面,这是很好的,但至少有一些页面被从实际上未保存为UTF-8的文件中拖动。 SSI只是抛出原始字节,它不尝试重新编码包含,使他们的字符集匹配它们被包括到的文件。



    你需要去。



    正如John所说,你可以 >通过对所有非A​​SCII字符使用字符引用避免编码问题,但这是一个巨大的痛苦。


    I created this 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 the website linked above all the common stuff was duplicated in each page. In order to improve the maintainability I refactored the pages to use server-side includes (SSI) so that the common parts are 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

    I uploaded the refactored site to this address, and as you can see it didn't quite work out. 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.

    Cheers, Don

    解决方案

    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.

    这篇关于服务器端包含和字符编码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆