I have this php script (test.php) which checks whether the page exists in mysql and it should return 404 status header but it returns 200 OK status. This causes soft 404 errors in console.
I tried to fix but it is simply not working. Here is my .htaccess. I migrated my site to SSL few months ago and i am redirecting all traffic to https from port 80.
RewriteEngine On
ErrorDocument 404 /404.shtml
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/[0-9]+\..+\.cpaneldcv$
RewriteCond %{REQUEST_URI} !^/[A-F0-9]{32}\.txt(?:\ Comodo\ DCV)?$
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]
RewriteEngine on
RewriteRule ^([0-9]+)-([0-9]+)-([0-9]+)/pressrelease([0-9]+)\.htm$ test.php?pressid=$4 [L]
and here is my test.php
<?php
include_once('dbc.php');
$pid = strip_tags(mysql_real_escape_string($_GET['pressid']));
$rs_dirs = mysql_query("select id,name from categories order by name") or die(mysql_error());
$rs_press = mysql_query("select *
from press
where id = '$pid'
and approved='1'
") or die(mysql_error());;
$total = mysql_num_rows($rs_press);
if (mysql_num_rows($rs_press) == 0) {
header("HTTP/1.1 404 Not Found");
include '404.shtml';
die();
}
What is the problem here and how do i fix it?