First of all I would get rid of that page thing. Your web-server already provides the requested resource, through REQUEST_URI variable. No need to pollute the query string with a useless variable that could be easily overwritten. So make your rule just RewriteRule ^([a-z_-]+)$ index.php [L,QSA]
(the original query string is a goofgood thing to keep, so we're adding QSA
)
$page = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$page = trim($page, "/"); // original request may have them
if (in_array($page, ['index.php', 'home'], true)) {
header("Location: /", true, 301);
die; // always die if there is any code after Location:
}
$page = $page ?: 'home'; // make it home if empty
if (preg_match('~^[a-z_-]+$~', $page) && file_exists("inc/$page.php")) {
require "inc/$page.php";
include "tpl/$page.tpl.php";
} else {
http_response_code(404);
}
HTTP status codes are not for decoration. They must be used in the exact situations they are intended for. When a page is not found, your server should respond with 404 status, not 302. I would advise to create designatedcorresponding pages (i.e. 404.php, 500.php) in the inc directory and include them along with setting appropriate HTTP status instead of redirect.