logo
Apache Lounge
Webmasters

 

About Forum Index Downloads Search Register Log in RSS X


Keep Server Online

If you find the Apache Lounge, the downloads and overall help useful, please express your satisfaction with a donation.

or

Bitcoin

A donation makes a contribution towards the costs, the time and effort that's going in this site and building.

Thank You! Steffen

Your donations will help to keep this site alive and well, and continuing building binaries. Apache Lounge is not sponsored.
Post new topic   Forum Index -> Apache View previous topic :: View next topic
Reply to topic   Topic: Apache 2.2.3 wrong headers?
Author
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Tue 29 Aug '06 16:23    Post subject: Apache 2.2.3 wrong headers? Reply with quote

Hello,

Im running apache 2.2.3 with php 5.1.5 on winxp. I configured the httpd.conf so the 404 error return a 404 header using the following php script :
<?php
header("HTTP/1.0 404 Not Found");
?>
It still return 200 OK .. what am i doing wrong?
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Tue 29 Aug '06 16:49    Post subject: Reply with quote

What did you change in your httpd.conf?

ErrorDocument 404 "your.php" ?

Than you don't have to set the 404 header by the script. Apache will do it itself!

the ErrorDocument 404 is only a chance to make that page look nicer or give you the chance to run a script that i.e. sends you an email that the page is missing
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Tue 29 Aug '06 16:55    Post subject: Reply with quote

Yes i did change the httpd.conf like you said. But if i check, it doesn't return the right header... Google says it returns 200 OK instead of 404... even if i force it in php..
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Tue 29 Aug '06 17:42    Post subject: Reply with quote

Uli wrote:
Yes i did change the httpd.conf like you said. But if i check, it doesn't return the right header... Google says it returns 200 OK instead of 404... even if i force it in php..

I didn't sad that you should change that! That was an example!
I asked "what did you chnage?

Why google says 200 ok? What did you checked with google? Is there an example what you did do?


Before that remove the ErrorDocument 404 "your.php" ? you changed in httpd.conf
restart apache

if you run Apache
type in your browser
http://127.0.0.1/realynottherefile.axcd
or if you run your Apache on Port 8080
http://127.0.0.1:8080/realynottherefile.axcd

Apache will show you a 404 error page!
404 means file not found!
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Tue 29 Aug '06 17:56    Post subject: Reply with quote

It was already changed... and already restarted before i post.
Now if you add your site into google, you can admin it sort of using
https://www.google.com/webmasters/sitemaps/siteoverview?hl=en
To verify your site you need to create and upload a html page as google wants it and then it check the header of your 404 page ..
In my case it always return 200 OK (probably cause the 404 page exists) and i can't use the meta tags verification system because my domain forwarding won't allow me to add custom tags with no masking.
So my problem remains, apache 2.2.3 returns a status of 200 instead of 404 for the 404 error page... even if it displays the 404 page, i'm talking about HEADERS here, not pages..
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Tue 26 Sep '06 18:43    Post subject: Reply with quote

anyone????

my 404.php has that header :
<?php
header("HTTP/1.0 404 Not Found");
?>

my ht.acl has :
ErrorDocument 404 /error/404.php

my httpd.conf has :
ErrorDocument 404 /error/404.php

so what's wrong?????
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3053
Location: Hilversum, NL, EU

PostPosted: Tue 26 Sep '06 19:39    Post subject: Reply with quote

Try to test with http://web-sniffer.net/

And see what that says.

Steffen
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Tue 26 Sep '06 22:27    Post subject: Reply with quote

Heres the detail when i point to my 404 page...

Connect to 204.xx.xxx.xx on port 80 ... ok
GET /error/404.php HTTP/1.1[CRLF]
Connection: close[CRLF]
Accept-Encoding: gzip[CRLF]
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5[CRLF]
Accept-Language: en-us,en;q=0.5[CRLF]
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7[CRLF]
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.0.7) Gecko/20060909 Firefox/1.5.0.7 Web-Sniffer/1.0.24[CRLF]
Referer: http://web-sniffer.net/[CRLF]

It says the header returns:
HTTP Status Code: HTTP/1.1 200 OK

if i point to a non existing page it returns:
HTTP Status Code: HTTP/1.1 302 Moved Temporarily

i don't undestand..
Back to top
Steffen
Moderator


Joined: 15 Oct 2005
Posts: 3053
Location: Hilversum, NL, EU

PostPosted: Tue 26 Sep '06 22:54    Post subject: Reply with quote

Indeed all you done, looks ok.

Who knows, try to use the full path:

ErrorDocument 404 x:/xxx/error/404.php

and who knows, between single quotes:

header('HTTP/1.0 404 Not Found');


Steffen
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Wed 27 Sep '06 6:17    Post subject: Reply with quote

i've tried everything, i still get wrong headers... dunno what to do....
Back to top
Jorge



Joined: 12 Mar 2006
Posts: 376
Location: Belgium

PostPosted: Wed 27 Sep '06 9:15    Post subject: Reply with quote

You don't need to privide a header for the ErrorDocuments you set in apache. Apache will add the correct one (404, 500, 302...)

You only need to do that in php for example if the page exist but because of a wrong input the usermade you can return a 404 so search engines etc wo'nt index it.
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Wed 27 Sep '06 17:14    Post subject: Reply with quote

if i don't add anything, it acts the same... the header of the 404 page return 200 ok....
Back to top
James Blond
Moderator


Joined: 19 Jan 2006
Posts: 7294
Location: Germany, Next to Hamburg

PostPosted: Thu 28 Sep '06 10:26    Post subject: Reply with quote

Uli wrote:

GET /error/404.php HTTP/1.1[CRLF]


You call the 404.php itself! Don't do that!
try http://yourIP/not-existing-page.htm
Back to top
Uli



Joined: 28 Aug 2006
Posts: 17

PostPosted: Thu 28 Sep '06 22:31    Post subject: Reply with quote

i call a php page cause i wanted to force the header to return 404...
If i call a regular 404 page, it returns 200 ok...
Back to top
alangiv



Joined: 18 Oct 2006
Posts: 1

PostPosted: Wed 18 Oct '06 17:44    Post subject: same problem Reply with quote

U;i, I've been doing the same thing (trying to change headers). I can't understand why no one understands the problem (i.e that you want to raise an HTTP error). Apache seems to return 200 OK no matter what. Guess its an apache thing.
Back to top
tdonovan
Moderator


Joined: 17 Dec 2005
Posts: 611
Location: Milford, MA, USA

PostPosted: Thu 19 Oct '06 3:08    Post subject: Reply with quote

I'm not seeing the same results with Apache 2.2.3 and PHP 5.1.6 on Windows 2000.

I have this directive in httpd.conf:
    ErrorDocument 404 /fnf.php

If I request a nonexistent page, the response status is 404 as expected:
Quote:
GET /NoSuchPage.html HTTP/1.1
Host: localhost

HTTP/1.1 404 Not Found
Date: Thu, 19 Oct 2006 00:54:21 GMT
Server: Apache/2.2.3 (Win32) mod_ssl/2.2.3 OpenSSL/0.9.8c SVN/1.4.0 DAV/2 PHP/5.1.6 mod_perl/2.0.3-rc1 Perl/v5.8.8
X-Powered-By: PHP/5.1.6
Vary: Accept-Encoding
Content-Length: 119
Content-Type: text/html

When I directly request fnf.php I get 200 OK - but I expect to get a 200 response when I request it directly.

If I put:
    <?php header("HTTP/1.0 404 Not Found"); ?>
as the first line of fnf.php, then every request always returns a status of HTTP/1.1 404 Not Found, regardless of how I request it.

Maybe it is a PHP 5.1.5 thing rather than an Apache thing?

You might try using all three arguments to the header function, like:
    <?php header("HTTP/1.0 404 Not Found", true, 404); ?>
This isn't necessary for me - but maybe it will help with PHP 5.1.5.

-tom-
Back to top


Reply to topic   Topic: Apache 2.2.3 wrong headers? View previous topic :: View next topic
Post new topic   Forum Index -> Apache