You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@httpd.apache.org by Zach Uram <ne...@gmail.com> on 2008/08/17 01:08:19 UTC

[users@httpd] please help - adding Chinese character sets to Apache

Hello,

I downloaded a chinese webpage onto my remote server using wget (where
I host my Apache 1.3 webserver - running Debian testing release) and
when I view it the Chinese characters have been replaced with ASCII
gibberish. Yet the original Chinese page displays fine in Firefox on
my local machine (Ubuntu 6.06) and I can even see the Chinese
characters in my local console in Ubuntu when I load the file in
emacs.

Here is my download script:
http://www.jesujuva.org/bob/bob.sh

Here is the garbled page after it downloads it:
http://www.jesujuva.org/bob/www.dajun.com.cn/kaimushi.htm

The meta tags indicate the content type:

<meta http-equiv="Content-Language" content="zh-cn">
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">

I think my Apache is not serving the GB2312 charset. So I looked here:

http://httpd.apache.org/docs/2.0/mod/mod_mime.html#addcharset


How can I verify what charsets my Apache 1.3.34 server currently
supports? I read that section on AddCharset but it doesn't say exactly
what file should I edit to add this to it? How do I know what are
valid charsets (spelled the way Apache expects them)? I can find no
mod_mime when I do an 'apt-cache search mod_mime' but I did find a
package:

libapache2-mod-mime-xattr - Apache2 module to get MIME info from
filesystem extended attributes

Will apache2 modules work with my Apache 1 webserver? The server is
now running Debian testing release since I upgraded it. I guess I want
something like:

AddLanguage zh-cn .zh-cn
AddCharset  gb2312 .gb

Does that look good? I am just guessing since I don't know the proper
extension that Apache maps to gb2312 and I am following the example
for the AddLanguage so not 100% sure if I did that correctly. I would also like
to support the Big5 chinese character set so can someone tell me what to add
for this as well.

Regards,
Zach

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org


Re: [users@httpd] please help - adding Chinese character sets to Apache

Posted by Krist van Besien <kr...@gmail.com>.
On Sun, Aug 17, 2008 at 01:08, Zach Uram <ne...@gmail.com> wrote:

> <meta http-equiv="Content-Language" content="zh-cn">
> <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
>
> I think my Apache is not serving the GB2312 charset. So I looked here:

Apache does not "serve" character sets. Apache will pass a html page
on to the browser, which will render it. The browser guesses what
charset the use to display the page based on a lot of different items.
Headers passed along with the response, meta headers in the html
etc... Sometimes the browser guesses wrongly what the correct
character set is. You can then set the charset manually (in firefox
choose view/character encoding) and this ought to make the page render
correctly.
Offcourse you want this to happen automatically. Your problem is
probably due to apache not responding with the correct content-type
header. What you should do is the following:
- Use a tool that allows you to see the whole request, including
headers. You are allready using wget, you could use the following
command:  wget --debug <url>, and use this to fetch both the page from
the original server and from your own server. Watch the "Content-Type"
header. If this header is not correct on your server you have found
the cause of your problem.

If your server sends the wrong content-type header (which I'm fairly
sure is the source of your problem) you need to indeed add an
"AddCharset" directive. This directive looks like this:

AddCharset <character map> <extention>

So

AddCharset  gb2312 .gb

would add charset gb2312 to the content-type header for all files with
an extention ending in .gb. So you would need to rename all your files
encoded in gb2312. The same would apply if you want to use big5
encoding.

If all your gb2312 encoded files are in the same directory (or in
directories sharing a common root) than you could use something like
this:

<Directory /var/www/chinesesite/>
AddDefaultCharset gb2312
</Directory>

This way all files from this directory will get served with a
content-type header with the gb2312 charset.

A last tip: If you rename all your gb2312 encoded files to something
like index.html.gb you don't need to change all the links to these
pages if you set the following option.
Option +Multiviews
This way if a request comes for index.html, but no index.html exists
apache will search for index.html.*. You couuld then even have both an
index.html.gb
and
index.html.big5
with the proper character set assigned to each using AddCharset.
Apache will then serve one of both files when a request for index.html
comes, depending on what the browser prefers.

Krist














-- 
krist.vanbesien@gmail.com
krist@vanbesien.org
Bremgarten b. Bern, Switzerland
--
A: It reverses the normal flow of conversation.
Q: What's wrong with top-posting?
A: Top-posting.
Q: What's the biggest scourge on plain text email discussions?

---------------------------------------------------------------------
The official User-To-User support forum of the Apache HTTP Server Project.
See <URL:http://httpd.apache.org/userslist.html> for more info.
To unsubscribe, e-mail: users-unsubscribe@httpd.apache.org
   "   from the digest: users-digest-unsubscribe@httpd.apache.org
For additional commands, e-mail: users-help@httpd.apache.org