Hello, everybody, I faced a problem, which has took me already 2 days without any success . In my .htaccess file there are 2 directives (amongst others), which I know for sure confilct each with other: ErrorDocument 404 /404.php RewriteRule ^(.+)$ index.php?page=$1 [NC,QSA] Code (markup): All HTTP requests are sent to index.php, and the program then checks $_GET['page'] variable, and returns 404 HTTP response if needed. Here is the code: if ( $_GET['page'] != 'about.html' ) { header('HTTP/1.0 404 Not Found'); exit; } PHP: Inside my raw logs I can see that this works just fine (returns 404 HTTP response), look at the following log file line: 91.207.210.62 - - [29/Sep/2011:09:20:33 -0500] "GET /nonexisting_filename.html HTTP/1.1" 404 38 "-" "Mozilla/5.0 (Windows NT 5.1) AppleWebKit/535.1 (KHTML, like Gecko) Chrome/14.0.835.186 Safari/535.1" Code (markup): The problem is it still shows browser default error page. If I remove the RewriteRule from second line it works just fine, but I don't understand why wouldn't it work if the PHP program returns 404 HTTP response? How can this be solved. Maybe I need to returns additional headers? Like, say: if ( $page != 'about.html' ) { header('HTTP/1.0 404 Not Found'); header('Location: /404.php'); exit; } PHP: ? Would this work? I need it to both return 404 HTTP response and redirect visitors to 404.php. Any help would be much appreciated. Dennis.
Hi, I'm not sure if it orks, anyay, try add this directive [NC,L] to first instruction, like this: ErrorDocument 404 /404.php [NC,L] RewriteRule ^(.+)$ index.php?page=$1 [NC,QSA] Code (markup):
Okay, thanks for recommendation. I solved the problem the other way. I removed ErrorDocument directive at all, for I though the rule RewriteRule ^(.+)$ index.php?page=$1 would catch all and any request and direct it to index.php, and inside index.php I added the following code for cases when I need 404 error response: if ( $page != 'about.html' ) { header('HTTP/1.0 404 Not Found'); include('404.php'); exit; } PHP: This works perfectly, returns 404 HTTP response (needed for search engines correct behavior), and at the same time loads 404.php file into browser to show visitors appropriate message or redirect them to appropriate page.