|
13 | 13 | define('MAHO_ROOT_DIR', dirname(__DIR__)); |
14 | 14 | define('MAHO_PUBLIC_DIR', __DIR__); |
15 | 15 |
|
| 16 | +// Early exit for missing static assets — avoids full bootstrap just to return a 404. |
| 17 | +// Web servers should handle this natively, but this is a safety net for environments |
| 18 | +// where that's not configured (php -S dev server, FrankenPHP defaults, shared hosting). |
| 19 | +$requestPath = parse_url($_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH) ?: '/'; |
| 20 | +if ($requestPath !== '/') { |
| 21 | + $ext = strtolower(pathinfo($requestPath, PATHINFO_EXTENSION)); |
| 22 | + $staticExts = [ |
| 23 | + 'jpg', 'jpeg', 'png', 'gif', 'webp', 'avif', 'svg', 'svgz', 'ico', 'bmp', 'apng', |
| 24 | + 'css', 'js', 'mjs', 'map', 'woff', 'woff2', 'ttf', 'otf', 'eot', |
| 25 | + 'mp3', 'mp4', 'ogg', 'webm', 'wav', 'flac', 'aac', 'm4a', 'm4v', 'ogv', 'mov', |
| 26 | + 'pdf', 'doc', 'docx', 'xls', 'xlsx', 'ppt', 'pptx', |
| 27 | + 'zip', 'gz', 'tar', 'rar', '7z', |
| 28 | + ]; |
| 29 | + if (in_array($ext, $staticExts, true)) { |
| 30 | + http_response_code(404); |
| 31 | + exit; |
| 32 | + } |
| 33 | +} |
| 34 | + |
16 | 35 | require MAHO_ROOT_DIR . '/vendor/autoload.php'; |
17 | 36 |
|
18 | 37 | #\Maho\Profiler::enable(); |
|
0 commit comments