Forum Moderators: phranque
I've problem with mod rewrite "again"...
I need to prevent access to url without query, which return 404 header from noexist.php
<?php
header("HTTP/1.0 404 Not Found");
?>
example:
blabla.php should return 404 / not found
blabla.php?query=whatever should return 200 / success
I've tried this:
RewriteRule ^blabla\.php$ noexist.php [NC]
Both url "success" returning 404 / not found
Any suggestion?
That RewriteCond should check to see if QUERY_STRING is blank.
Alternatively, your script could be programmed to directly return a 404 HEADER and a suitable error message if the parameters were blank or missing.
.
Your script should also return a 404 status code if any query string value is non-valid.
<?php
function errPageURL() {
if (preg_match('/blabla.php$¦otherblabla.php$/',$_SERVER['REQUEST_URI'],$matches)) {
header($_SERVER["SERVER_PROTOCOL"]." 404 Not Found");
exit;
}
return true;
}
?>
<?php
errPageURL()
?>
If *all* queries to 'blahblah.php' should result in a 404, then you don't need the script and can do this in .htaccess as gismd describes above. But if any queries are valid, then you need your script to take the query parameters, check your database with them, and decide if it can return a valid 'page' of content.
Jim