What is the best way to retrieve the requested page when handling errors in PHP?

When handling errors in PHP, it is important to have a way to gracefully handle the error and redirect the user to a specific page, such as an error page or a default page. One way to retrieve the requested page when an error occurs is to use the header() function to redirect the user to the desired page. By checking for specific error conditions and redirecting accordingly, you can provide a better user experience and maintain control over the flow of your application.

// Check for specific error condition
if ($error_condition) {
    header("Location: error_page.php");
    exit();
}