Move asset serving logic to before language extraction
Remove redundant static file serving logic for content directory
This commit is contained in:
parent
1503e2c066
commit
69243cb7b1
1 changed files with 8 additions and 20 deletions
|
@ -13,6 +13,14 @@ $requestUri = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '/';
|
|||
$hasTrailingSlash = str_ends_with($requestUri, '/') && $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
|
||||
$currentLang = $defaultLang;
|
||||
$pathParts = explode('/', $requestPath);
|
||||
|
@ -351,26 +359,6 @@ function renderFile(string $filePath): void {
|
|||
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
|
||||
if (empty($requestPath)) {
|
||||
// Try language-specific frontpage first, then default
|
||||
|
|
Loading…
Add table
Reference in a new issue