使用switch case爆破url页面

The script working fine but when i try to access an random page i dont get any error 404,

Example:

enter image description here

how i do if the page does not exist to display an error message like 404 error?

# htaccess: #
RewriteEngine On

RewriteBase /bogdan/

RewriteCond %{REQUEST_FILENAME} !-d

RewriteCond %{REQUEST_FILENAME} !-f

RewriteRule ^(.+)$ index.php?url=$1 [QSA,L]

RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]

RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# php splitter: #

$url = isset($_GET['url']) ? $_GET['url'] : 'home';

$url = filter_var(rtrim($url, '/'), FILTER_SANITIZE_URL);

$url = explode('/', $url);

switch ($url[0]) {

    case 'home':
        $page_name = 'Home';
        $page_file = 'pages/1-home.php';
        break;

    case 'another':
        $page_name = 'Another';
        $page_file = 'pages/2-another.php';
        break;

    default:
        $page_name = 'Home';
        $page_file = 'pages/1-home.php';
        break;

}

$page_file = str_replace(["/"], DIRECTORY_SEPARATOR, $page_file);

Change the code in your default: section to return HTTP 404 code and generate a proper template. See this question as reference.

PS. You seem to check only the first part of the URL, i.e. $_GET[0], but looks like you don't process any subsequent ($_GET[1],...) parts of it. In general I would advise you to either build your app on any mainstream framework with proper routing package in it or if you don't feel like using any fullstack PHP framework, you can install just any routing package via composer. E.g. symfony/routing

Thanks, solved.

if (sizeof($url) != 1) {
    header('Location: ../404');
}
else {
    // nothing
}

default:
    $page_name = 'Error';
    $page_file = 'pages/errors/404.php';
    break;