<?php
$requestUri = $_SERVER['REQUEST_URI'];

// Remove query string
$path = parse_url($requestUri, PHP_URL_PATH);
$slug = trim($path, "/");

// If no slug, default to "home"
$page = $slug === '' ? 'home' : $slug;

// Path to PHP file
$filePath = __DIR__ . '/pages/' . $page . '.php';

// Debug output
// echo "Slug: $slug<br>";
// echo "Looking for file: $filePath<br>";

if (file_exists($filePath)) {
    include($filePath);
    exit();
} else {
    http_response_code(404);
    include(__DIR__ . '/pages/404.php');
    exit();
}
?>
