tc1 Posted July 15, 2007 Share Posted July 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
trq Posted July 15, 2007 Share Posted July 15, 2007 Can we see this header call? header('Location http://domain/foo.php') does not send a 301 or 302. Quote Link to comment Share on other sites More sharing options...
tc1 Posted July 15, 2007 Author Share Posted July 15, 2007 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. Quote Link to comment Share on other sites More sharing options...
tc1 Posted July 15, 2007 Author Share Posted July 15, 2007 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" Quote Link to comment Share on other sites More sharing options...
steviewdr Posted July 17, 2007 Share Posted July 17, 2007 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 Quote Link to comment Share on other sites More sharing options...
tc1 Posted July 17, 2007 Author Share Posted July 17, 2007 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? Quote Link to comment Share on other sites More sharing options...
steviewdr Posted July 18, 2007 Share Posted July 18, 2007 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 Quote Link to comment Share on other sites More sharing options...
tc1 Posted July 18, 2007 Author Share Posted July 18, 2007 I tried it with PHP 5.2.2 and the log still shows 200. I scoured the web and can't seem to find any information. But thanks for trying to help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.