« Previous Next »

Thread: PHP custom error page returns 200 instead of 404

Last post 07-03-2008 6:20 AM by Alex.W474. 3 replies.

Average Rating Rate It (5)

RSS

Page 1 of 1 (4 items)

Sort Posts:

  • 07-02-2008, 2:32 PM

    • blaine
    • Not Ranked
    • Joined on 07-02-2008, 6:05 PM
    • Posts 2

    PHP custom error page returns 200 instead of 404

    I created a custom error page in PHP that I want to handle all my 404 errors (error.php).  It logs the requested page and displays a nice message to the user.  I have set error.php as the URL that IIS should serve in the event of a 404 error. 

    error.php displays correctly (is parsed) when I enter a non-existent url but when I check the response headers I find a 200 response code.

    When I use the header( ) function to send a 404 response code from error.php, calling a non-existent page results in a 404 response code (which is what I want) but no html is sent (which is not what I want).

    I am running PHP 5.2 as a fast-cgi on IIS 6 on windows 2003 server.  I have full access to the server.

    Does anyone know how to get IIS to return both the custom error page and a 404 response code?

    Is it possible that IIS thinks that error.php does not exist because it is sending a 404 code?

     


     

     

  • 07-02-2008, 3:58 PM In reply to

    Re: PHP custom error page returns 200 instead of 404

    How do you know that server does not return content after the response?

    Try to disable the IE Show Friendly Errors option and try again: http://www.witsuite.com/support/knowledge-base/general/disable-ie-friendly-error-messages.php

  • 07-02-2008, 5:41 PM In reply to

    • blaine
    • Not Ranked
    • Joined on 07-02-2008, 6:05 PM
    • Posts 2

    Re: PHP custom error page returns 200 instead of 404

    I use FireFox not IE.

    I know the server is not returning content (just the header) because the page that is returned is blank (has no source code) and shows as zero size in Yslow (a FireFox extension).

     

     


     

  • 07-03-2008, 6:20 AM In reply to

    Re: PHP custom error page returns 200 instead of 404

    Well, on my Windows XP Pro I've created folder c:\inetpub\wwwroot\test, created application in IIS management console, set 404 error page to /test/404.php and created file:

     <?php
    header('HTTP/1.1 404 Not Found');
    echo "test";

    Then open  http://localhost/test/asdf and get "test" content.

    Firebug says that it is 404.

     My FastCGI INI:

    [Types]
    php = PHP-5.2
    [PHP-5.2]
    ExePath = C:\WITSuite\Languages\PHP-5.2\php-cgi.exe
    Arguments = -c C:\WITSuite\Configuration\IIS\PHP-5.2\php.ini
    QueueLength = 999
    MaxInstances = 20
    InstanceMaxRequests = 500
    ActivityTimeout = 600
    ResponseBufferLimit = 0

Page 1 of 1 (4 items)
Microsoft Communities