How can the "Host header" affect the status code of a website, and what role does Apache play in this scenario?

The "Host header" can affect the status code of a website if it does not match the server configuration. This can lead to the server returning a status code of 400 or 404. Apache can play a role in this scenario by allowing the server to handle requests based on the Host header.

<?php
if ($_SERVER['HTTP_HOST'] != 'example.com') {
    header("HTTP/1.1 404 Not Found");
    exit();
}