In what ways can error pages be utilized in PHP to mimic the functionality of mod_rewrite on servers where it is not available?

When mod_rewrite is not available on a server, error pages can be utilized in PHP to mimic its functionality by redirecting requests to a single PHP script that will handle the routing based on the requested URL. This script can parse the URL and determine the appropriate action to take, such as including the corresponding PHP file or displaying a custom error page.

<?php
// .htaccess file
ErrorDocument 404 /error.php

// error.php
$request_uri = $_SERVER['REQUEST_URI'];
if ($request_uri == '/page1') {
    include 'page1.php';
} elseif ($request_uri == '/page2') {
    include 'page2.php';
} else {
    include '404.php';
}
?>