Jump to content

Apache log always shows 200 instead of actual status code sent


tc1

Recommended Posts

When I have a PHP script send out redirect header, it sends out a 301 or 302 code and the redirect is successful, but the Apache log always shows a 200 code instead.  No matter what header or code my PHP scripts send, it always shows as 200 in the log.  Any ideas why?  In case it matters, PHP is running as CGI.

Link to comment
Share on other sites

Here is what is in my script:

 

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://domain.com");

 

I have also tried header("Status: 301 Moved Permanently");

 

The reason this is a problem is that when I examine the log I have no way of knowing which entries are successful redirects.  Sometimes a crawler will request a file that is supposed to redirect, and when the log shows 200 instead of 301 I have no way of knowing what was actually sent.

Link to comment
Share on other sites

Also, here are the headers that I receive from the server:

 

----------------------------------------

HTTP/1.x 301 Moved Permanently

 

Date: Sun, 15 Jul 2007 22:41:55 GMT

 

Server: Apache/2.0.54 (Unix) PHP/4.4.7 mod_ssl/2.0.54 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2

 

X-Powered-By: PHP/4.4.7

 

Location: http://<domain>/test2.php

 

Vary: Accept-Encoding

 

Keep-Alive: timeout=15, max=100

 

Connection: Keep-Alive

 

Transfer-Encoding: chunked

 

Content-Type: text/html

----------------------------------------

 

And this is what appears in the log:

 

<ip deleted> - - [15/Jul/2007:15:41:55 -0700] "GET /test.php HTTP/1.1" 200 390 "-" "Mozilla/5.0 (Macintosh; U; Intel Mac OS X; en-US; rv:1.8.1.1) Gecko/20061223 Firefox/2.0.0.1"

 

 

Link to comment
Share on other sites

The reason you see a 200 in apache logs is because - apache access your file test.php fine. The file *is* there and apache reads it OK. I.e. apache gives it a 200.

 

Now - inside the file you have a redirect sending a 301 to the client. This is AFTER apache has accessed test.php and given it a 200 in the access.log. So apache records a 200, but the client is sent a 301 by the php script.

 

-steve

Link to comment
Share on other sites

Steve, if I run the same script on another server with a different web hos the log shows the correct codes.  The only difference is that the other server is running PHP as a module, whereas this one is running as a CGI.  Could that be the reason why, or is there some setting that can be changed?

Link to comment
Share on other sites

Some tests I done:

Using:

<?php

header("HTTP/1.1 301 Moved Permanently");

header("Location: http://www.google.ie");

?>

 

I get via phpapache module: HTTP/1.1" 301

 

Via php cgi I get: HTTP/1.1" 301

 

 

So its both the same for me using PHP apache module and the cgi module.

 

It could be a php4 issue. It could be a timeout issue and it been cached etc.

 

-steve

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.