Move asset serving logic to before language extraction

Remove redundant static file serving logic for content directory
This commit is contained in:
Ruben 2025-10-02 23:51:54 +02:00
parent 1503e2c066
commit 69243cb7b1

View file

@ -13,6 +13,14 @@ $requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '/';
$hasTrailingSlash = str_ends_with($requestUri, '/') && $requestUri !== '/'; $hasTrailingSlash = str_ends_with($requestUri, '/') && $requestUri !== '/';
$requestPath = trim($requestUri, '/'); $requestPath = trim($requestUri, '/');
// Check for assets in /custom/assets/ served at root level (before language extraction)
$assetPath = dirname(__DIR__) . '/custom/assets/' . $requestPath;
if (file_exists($assetPath) && is_file($assetPath)) {
header('Content-Type: ' . (mime_content_type($assetPath) ?: 'application/octet-stream'));
readfile($assetPath);
exit;
}
// Extract language from URL // Extract language from URL
$currentLang = $defaultLang; $currentLang = $defaultLang;
$pathParts = explode('/', $requestPath); $pathParts = explode('/', $requestPath);
@ -351,26 +359,6 @@ function renderFile(string $filePath): void {
exit; exit;
} }
// Check for assets in /custom/assets/ served at root level
$assetPath = dirname(__DIR__) . '/custom/assets/' . $requestPath;
if (file_exists($assetPath) && is_file($assetPath)) {
header('Content-Type: ' . (mime_content_type($assetPath) ?: 'application/octet-stream'));
readfile($assetPath);
exit;
}
// Check for static files in content directory
$contentFilePath = rtrim($contentDir, '/') . '/' . ltrim($requestPath, '/');
if (file_exists($contentFilePath) && is_file($contentFilePath)) {
$ext = pathinfo($contentFilePath, PATHINFO_EXTENSION);
// Only serve non-PHP/non-HTML/non-MD files as static assets
if (!in_array($ext, ['php', 'html', 'md'])) {
header('Content-Type: ' . (mime_content_type($contentFilePath) ?: 'application/octet-stream'));
readfile($contentFilePath);
exit;
}
}
// Handle frontpage // Handle frontpage
if (empty($requestPath)) { if (empty($requestPath)) {
// Try language-specific frontpage first, then default // Try language-specific frontpage first, then default