How can PHP developers handle cases where websites redirect to custom 404 pages when checking for availability?

When websites redirect to custom 404 pages, PHP developers can handle this by checking the response code of the URL. If the response code is 404, then the website is redirecting to a custom 404 page. To handle this, developers can use the PHP cURL extension to make a request to the URL and check the response code.

$url = 'https://example.com/page';
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_NOBODY, true);
curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);

if($httpCode == 404) {
    echo "Website is redirecting to a custom 404 page.";
} else {
    echo "Website is available.";
}