Forum Moderators: coopster

Message Too Old, No Replies

problem with custom 404 error page on IIS 6

returned page headers not matching php header

         

jezra

11:12 pm on Jan 13, 2006 (gmt 0)

10+ Year Member



On a server running Windows 2003 Server and IIS 6, I have a custom 404 error page with that will either redirect based on the requested URI or will display my 404 message. For example when a user tries to go to http://www.example.com/some_file.htm and the file doesn't exist but http://www.example.com/some_file.php does exist, the script will run the following:
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.example.com/some_file.php");

If the script doesn't perform a redirect, then the script will run
header("HTTP/1.1 404 Not Found"); and then display an error message.

My problem is this, when I run header("HTTP/1.1 404 Not Found"); I get a blank page. I checked the header output using curl -D and all of my error codes are appended with "OK". When testing the 301, I get "HTTP/1.1 301 OK" and testing the 404 I get "HTTP/1.1 404 OK". If I remove header("HTTP/1.1 404 Not Found"); from my script, my error message is displayed but the header returns "HTTP/1.1 200 OK". Has anyone else had this problem and found a solution?

coopster

10:29 pm on Jan 16, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Are you saying that your 404 header is not returning your custom 404 page [webmasterworld.com]?

jezra

11:49 pm on Jan 16, 2006 (gmt 0)

10+ Year Member



hey coopster,
I can see where I was a bit vague and I'll try to clear things up a bit. When a visitor to my site looks for a page that doesn't exist, the server software sends the user to my script. Depending on what the user requested, my script will either 302 and redirect, or 404 and display a sitemap. However, when my script executes the following code
header("HTTP/1.1 404 Not Found");
The browser receives "HTTP/1.1 404 OK"

coopster

12:44 am on Jan 17, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So you are wondering where the "OK" is coming from in the 404 response as opposed to the "Not Found"? Are you certain that you are not sending that out in your header() function? What are you using to view your response headers?

jezra

6:11 pm on Jan 17, 2006 (gmt 0)

10+ Year Member



I'm using "curl" with the "-D" option to dump the headers to a text file.

jezra

11:04 pm on Jan 20, 2006 (gmt 0)

10+ Year Member



I have found a solution to the first part of my problem, the "301 moved permanently".
I changed my code from:
header("HTTP/1.1 Moved Permanently");
to
header("Status: 301 Moved Permanently");
This results in the expected headers to be sent to the client. The problem with '404 Not Found' still exists, and I will post the solution if I ever find one.