Send 404 header via PHP after .htaccess redirect -
i want create custom 404 page won't send 404 header, still send's 200 ok.
.htaccess
my .htaccess redirects every request index.php.
rewriteengine on rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d rewriterule ^ /index.php [nc,l]
index.php
the index.php handles url included .php files. controller.php parses url , pastecontent.php includes requested .php content-file.
//handle url require 'inc/controller.php'; //paste <head> require 'inc/site_header.php'; //paste <body> require 'inc/pastecontent.php'; //paste footer require 'inc/site_footer.php';
a closer controller.php:
as can see tried send 404-header, before there output.
//parse url function parse_path() { [...] return $path; } $path_info = parse_path(); $controller = $path_info['call_parts'][0]; //does page exist? function contentfound($c){ $found = true; switch ($c) { [...] default: $found = false; } return $found; } //if content not exist -> 404 if(!contentfound($controller)) { header($_server["server_protocol"]." 404 not found"); require 'inc/site_header.php'; require 'inc/pastecontent.php'; require 'inc/site_footer.php'; die(); }
actually tried put header($_server["server_protocol"]." 404 not found");?
on top of index.php, redirected still sends 200 ok. doing wrong?
as kimb-technologies pointed out in previous answer question, whitespace causes problem. if cannot find visible whitespace @ beginning of of php files, there might invisible whitespace on them, though.
sometimes utf-8 bom (byte order mark) present on files. invisible text editors, messes php headers.
google ways remove appropriate os, using bash, powershell or something. ide, such phpstorm, offer removal directly.
Comments
Post a Comment