View Full Version : Apache


haninaguib
I was wondering if anyone has had problems getting Apache
to server arabic pages?
I have set the charset to windows-1254 as well as ISO-8859-6
but it is not working.

The same pages are served properly by IIS

Thanks,
Hani

sattia
give more details please
also btw it is windows-1256 not windows-1254 I think it is a typo

haninaguib
Yes it is 1256, typo

I figured it out. I needed to add to add the following line to httpd.conf

AddDefaultCharset windows-1256

Thanks for replying though

Hani

uniball
Shouldn't the HTML page contain the charset encoding ? I think it should work independant of the apache setup!
ex:

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


Please correct me if i'm wrong !

hicham
Yes you're correct. Apache does not do any re-encoding to the pages served.
Language settings are used for multilingual web site like debian.org. To try it with mozilla, go to
Edit/Preferences/Navigator/Languages
click on the 'Add' button and choose 'Arabic [ar]' and move it to the top.
Now go to debian.org, the home page will be in arabic.
More on how this work on the server side can be found on:
http://httpd.apache.org/docs-2.0/content-negotiation.html

Hicham

haninaguib
Originally posted by uniball
Shouldn't the HTML page contain the charset encoding ? I think it should work independant of the apache setup!
ex:

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


Please correct me if i'm wrong !

Yes my pages do specify the charset. But that was not enough
for some reason I still needed the following line added to httpd.conf.

AddDefaultCharset windows-1256

The link Hicham provides seems to explain how and why, one
day I might try to understand it :)

Hani

sattia
Both of u hicham and uniball r right but u forgot a little bit something which is:
The AddDefaultCharset directive has an effect in two cases:
1 - The browser didnt provide a charset
2 - Overrides whats in META tag

haninaguib
Originally posted by sattia
Both of u hicham and uniball r right but u forgot a little bit something which is:
The AddDefaultCharset directive has an effect in two cases:
1 - The browser didnt provide a charset
2 - Overrides whats in META tag

Ok now I am getting confused.
Do I need to add the AddDefaultCharset? It does not seem to
work without it.

I dont want the clients to have to set up ANYTHING when they
view my pages, regardless of where they are viewing it from.

It seems to be working correctly since I added the AddDefaultCharset line (as well as specifying the charset on my
pages).

Or is that not the case. The other funny thing is that IIS seems
to work correctly with out me having to fiddle with it.

Hani

hicham
from http://www.w3.org/TR/html4/charset.html#spec-char-encoding :
"
How does a user agent know which character encoding has been used? The server should provide this information. The most straightforward way for a server to inform the user agent about the character encoding of the document is to use the "charset" parameter of the "Content-Type" header field of the HTTP protocol ([RFC2616], sections 3.4 and 14.17) For example, the following HTTP header announces that the character encoding is EUC-JP:

Content-Type: text/html; charset=EUC-JP

Please consult the section on conformance for the definition of text/html.

The HTTP protocol ([RFC2616], section 3.7.1) mentions ISO-8859-1 as a default character encoding when the "charset" parameter is absent from the "Content-Type" header field. In practice, this recommendation has proved useless because some servers don't allow a "charset" parameter to be sent, and others may not be configured to send the parameter. Therefore, user agents must not assume any default value for the "charset" parameter.

To address server or configuration limitations, HTML documents may include explicit information about the document's character encoding; the META element can be used to provide user agents with this information.

For example, to specify that the character encoding of the current document is "EUC-JP", a document should include the following META declaration:

<META http-equiv="Content-Type" content="text/html; charset=EUC-JP">
"
So you have 2 methodes to specify the charset, and I prefer setting it in the HTMLpages themselves.

Hicham

haninaguib
Originally posted by hicham
.....
So you have 2 methodes to specify the charset, and I prefer setting it in the HTMLpages themselves.

Hicham

Well that is what I thought, but with Apache UNLESS I added the line to httpd.conf it did not work. All my pages have ALWAYS had the
charset specified.

Hani

alaa
shouldn't ou be using unicode instead??

haninaguib
Originally posted by alaa
shouldn't ou be using unicode instead??

I dont know. I am new to all this, and only ran into this problem
when I was asked to host some pages for a friend.

If it is not too much of a silly question, how would I go about
doing that. i.e. How should my friend prepare his pages and
how would I set up (if needed) Apache?


Thanks everyone

Hani

uniball
hmmm
maybe your friend didn't put a meta tag in his HTML code ?
Can i have the URL for the site please ?
I'm just interested in this strange problem !!

haninaguib
Originally posted by uniball
hmmm
maybe your friend didn't put a meta tag in his HTML code ?
Can i have the URL for the site please ?
I'm just interested in this strange problem !!

No, the meta tag is there.

You should be able to see the site at

http://www.haninaguib.homeip.net/phprojekt/

Login: arabic
Passwd : arabic

My friend is actually simply creating an Arabic language file
for PhProjekt.

The link above is served by the latest version of Apache running
on my homepc. You should be able to see some Arabic on the
page (he has just started). BUT I did have to add that extra
line to my Apache configuration.

Once you have seen it, let me know and I will remove it so you can see what happens when it is not there.


Hani

uniball
working fine
+
Hey! i have the same problem here !!!!!
I've saved the page and put it under my httpd document root, and it's not displayed correctly!!!
No need to disturb yourself and remove the configuration option I'll have to dig and see where the problem is !
Apache/1.3.26

hicham
Same here.
I think it's a bug in mozilla based browsers, because konqueror displays the page correctly.

There's an open bug that looks similar to this one on:
http://bugzilla.mozilla.org/show_bug.cgi?id=200134

without apache directive, wget -S http://server/page.html shows:
Content-Type: text/html; charset=ISO-8859-1
I think in this case, mozilla does not take into consideration the META tag.

BUT the strange thing is when using an utf-8 charset, the page is correctly displayed.

May be s.o can report this to mozilla.org

Hicham

haninaguib
Originally posted by hicham
Same here.
I think it's a bug in mozilla based browsers, because konqueror displays the page correctly.

.......

May be s.o can report this to mozilla.org

Hicham

I have get it with IE and Netscape. I think it has something to
do with Apache since the same page works when being served
by IIS. Or more likely my page is not constructed properly.

Hani

uniball
I don't think it's an apache problem
I've wrote a very minimalistic http server the last night
when the server sends the charset header the page is not correctly displayed in phoenix
If it's not sent the page is fine
konquerer seems to handle it correctly
I agree that it's a bug in mozilla and mozilla based browserz!
Here's the code if anyone is interrested ;-)


/* A simple minimalistic httpd server
* Copyright (c) Mohammed Sameer <uniball@linux-egypt.org>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/

#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>

int
main (int argc, char *argv[])
{
int sockfd, newsockfd, clilen;
int portno = 80;
char buffer[256];
struct sockaddr_in serv_addr, cli_addr;
int n;
FILE *f = NULL;
char *tmp = NULL;
int enc = 0;
char *root = "/var/www/";
char *file = (char *) malloc (sizeof (char) * 100);

if (!file)
{
fprintf (stderr, "Couldn't allocate memory\n");
return 1;
}

if (argc >= 2)
{
enc = 1;
}

sockfd = socket (AF_INET, SOCK_STREAM, 0);

if (sockfd < 0)
{
fprintf (stderr, "Couldn't open socket\n");
return 1;
}

bzero ((char *) &serv_addr, sizeof (serv_addr));
serv_addr.sin_family = AF_INET;
serv_addr.sin_addr.s_addr = INADDR_ANY;
serv_addr.sin_port = htons (portno);

if (bind (sockfd, (struct sockaddr *) &serv_addr, sizeof (serv_addr)) < 0)
{
fprintf (stderr, "Couldn't bind socket\n");
return 1;
}

listen (sockfd, 5);
clilen = sizeof (cli_addr);
newsockfd = accept (sockfd, (struct sockaddr *) &cli_addr, &clilen);

if (newsockfd < 0)
{
fprintf (stderr, "Couldn't accept connection\n");
return 1;
}

bzero (buffer, 256);
n = read (newsockfd, buffer, 255);

if (n < 0)
{
fprintf (stderr, "Couldn't read from socket\n");
return 1;
}

tmp = buffer;
tmp += 4;
n = 0;

while (1)
{
if (buffer[n + 4] == ' ')
{
break;
}
++n;
}

strncpy (file, &buffer[4], n);

printf ("Got: %s\n File: %s\n", buffer, file);

tmp = (char *) malloc (sizeof (char) * 100);

if (!tmp)
{
fprintf (stderr, "Couldn't allocate memory\n");
return 1;
}

sprintf (tmp, "%s/%s", root, file);

f = fopen (tmp, "r");

if (!f)
{
fprintf (stderr, "Couldn't open file\n");
return 1;
}

if (enc == 1)
{
n =
write (newsockfd,
"HTTP/1.1 200 OK\nContent-Type: text/html; charset=windows-1252\n\n",
64);
if (n < 0)
{
fprintf (stderr, "Couldn't writing to socket\n");
return 1;
}
}

while (fread (buffer, 255, 1, f))
{
n = write (newsockfd, buffer, strlen (buffer));

if (n < 0)
{
fprintf (stderr, "Couldn't writing to socket\n");
return 1;
}
}

return 0;
}