Forum Moderators: phranque
my .htaccess has the following entry:
RewriteRule ^catalog/([^/]+)/([0-9]+)/([0-9]+)/$ products.php?category=$1&page=$2&per_page=$3 [QSA,L]
my PHP script has the following code:
header("HTTP/1.1 404 Not Found"); exit();
for some reason the request is not further redirected from PHP to a generic Apache's 404 page, the same that appears if I type some nonsensical URL.
header('Location: '.getenv('HTTP_HOST').'/custom_404.php', true, 404); exit(); << doesn't work either.
however... header('Location: 'www.google.ca', true, 301); exit(); << works.
what am I doing wrong? why wouldn't it redirect to a 404 page (either Apache's default or my custom one)?
thanks!
Once Apache passes control to your script, your script is fully responsible for the remainder of the content-handling phase.
Your PHP code should output the 404 status header (as you show above), and then it should "include" (e.g. using the PHP "require" directive) the contents of your custom_404.php error page.
You certainly *Do Not* want to 301/302 redirect to your error page -- In SEO terms, this is known as "suicide" because it will very likely damage your search rankings, and open your site up to at least one unpleasant competitor exploits...
Server config code and scripting have side effects extending to search engine rankings. Be careful, and especially never send a status response that does not comply with the HTTP protocol specification for that response.
Jim