<?php

declare(strict_types=1);

// Keep the repository root as a friendly, deployment-independent entry point.
// Build the redirect from REQUEST_URI instead of a relative Location header;
// some Apache Alias configurations otherwise expand the filesystem path.
$requestPath = (string)(parse_url((string)($_SERVER['REQUEST_URI'] ?? '/'), PHP_URL_PATH) ?: '/');
$requestPath = str_replace('\\', '/', $requestPath);
$basePath = basename($requestPath) === 'index.php'
    ? rtrim(str_replace('\\', '/', dirname($requestPath)), '/')
    : rtrim($requestPath, '/');
$target = ($basePath === '' || $basePath === '.') ? '/public/' : $basePath . '/public/';

header('Location: ' . $target, true, 302);
exit;
