What are the advantages of using a router in PHP for URL handling instead of htaccess?

When using a router in PHP for URL handling instead of htaccess, you have more control and flexibility over how your URLs are processed and routed within your application. This allows for cleaner and more organized code, easier debugging, and the ability to easily implement custom routing logic based on specific requirements.

// Router implementation in PHP
$request_uri = $_SERVER['REQUEST_URI'];

switch ($request_uri) {
    case '/':
        require 'home.php';
        break;
    case '/about':
        require 'about.php';
        break;
    case '/contact':
        require 'contact.php';
        break;
    default:
        http_response_code(404);
        require '404.php';
        break;
}