Apache log showing 200 instead of 302


#1

When any of my PHP scripts send out a redirect header, or if I redirect with .htaccess, it redirects successfully but my Apache log shows 200 instead of 301 or 302. When I examine a log I have no way of knowing which log entries are redirects. Any ideas why it shows 200?


#2

It sounds like you’re using the php header function:
http://www.w3schools.com/php/func_http_header.asp
This will redirect with a 200.

I think you need to tell php to write the fact that it’s a permanent redirect.

http://www.roscripts.com/snippets/show/81

Unless you’re writing a databased redirect script, why not just use apache to redirect? It’s simpler and uses less machine resources.

http://httpd.apache.org/docs/2.0/mod/mod_alias.html#redirectpermanent

Chris


#3

Thanks for the response. I am not able to use Apache to redirect since I need to run a MySQL query to determine which file to redirect to. I created a script with just these two lines:

header(“HTTP/1.1 301 Moved Permanently”);
header(“Location: http://domain.com/file”);

If I use that exact same script on my other web host the log shows the correct code, but only on Dreamhost does the log show 200 instead of the actual code. I contacted support and this is what they said:

"if I was taking a guess I’d say it’s a case where the php file itself is
getting accessed OK and returning a 200. "

I don’t understand why it would put a 200 code in the log when it never actually sent one.

Also, I need to make a correction in my original post - .htaccess does actually show the correct code in the log.


#4

Dreamhost support says that there is nothing they can do about it. I am wondering if anyone else gets the same result on a different server. I am on drumstick, so if anyone who is on a different server wouldn’t mind testing it I would really appreciate it.