<?php
$path = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH);
if (!is_string($path)) {
    http_response_code(400);
    exit;
}
if ($path === '/' || $path === '/site') {
    header('Location: /site/', true, 301);
    exit;
}
if (str_starts_with($path, '/site/')) {
    $entry = __DIR__ . '/site/index.php';
    if (!is_file($entry)) {
        http_response_code(404);
        exit;
    }
    $_SERVER['SCRIPT_NAME'] = '/site/index.php';
    $_SERVER['PHP_SELF'] = '/site/index.php';
    $_SERVER['SCRIPT_FILENAME'] = $entry;
    chdir(__DIR__ . '/site');
    require $entry;
    exit;
}
http_response_code(404);
