So, here is my problem. I have a phpld script running. In httacces, everything is redirected to index.php I want to implement custom 404 errors, so I have to handle them in index.php The code for handling is this: // Check page request, if not valid a http header 404 is sent $http_status = (!empty ($_REQUEST['httpstatus']) ? intval ($_REQUEST['httpstatus']) : request_status()); if ($http_status == 404) { header("HTTP/1.1 404 Not Found"); header("Location: http://www.mygreencorner.com/error404.php"); exit(); } The problem is that when I call the last header function, I am implicitly setting the header to 302, thus destroying the whole purpose of the error pages. What's the fix on this? THANKS
Hi David, thanks for replying. Unfortunately, it is not working: http://it.php.net/manual/en/function.header.php Any other toughs on this?
who's david? yes http://it.php.net/manual/en/function.header.php#78470 seems you need a 'true' as well: <?php // 301 Moved Permanently header("Location: /foo.php",TRUE,301); // 302 Found header("Location: /foo.php",TRUE,302); header("Location: /foo.php"); // 303 See Other header("Location: /foo.php",TRUE,303); // 307 Temporary Redirect header("Location: /foo.php",TRUE,307); ?> PHP: i see no reason why you can't use a 404 as well - and yes - i have been using a 301 redirect this way instead of a 302 (default one being sent by php). good luck
Ohh, sorry , I must be so tired I can't even read. I meant Dimitar, thank you I really appreciate this Thanks. But now I am in more fog that I was at the beginning. Actually, I am testing with http://web-sniffer.net Now, I get the good status, and web-sniffer even show that the location is: Location: http://www.mysite.com/error_page404.php But in my web browser, I still have the http://www.mysite.com/gsdfgdgfdgdfgdf page, and the usual error page you see from google toolbar, instead of my custom one.
try to remove the header("HTTP/1.0 404 Not Found"); ? also - do you have any Errordocument directives in htaccess?
no, I have commented that already. (header("HTTP/1.0 404 Not Found") I think the htaccess does come into equation, as we are already at the part of executing php. Htaccess is run before this, all queries are forwarded to index.php, and in here we can play. I don't have any ErrorDocument in htaccess, but I already tried with and without, with no success.