-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathrouter.php
More file actions
26 lines (21 loc) · 644 Bytes
/
Copy pathrouter.php
File metadata and controls
26 lines (21 loc) · 644 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
<?php
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$root = __DIR__;
// Deliver real files directly, e.g. /vendor/... or /dist/...
$file = realpath($root . $uri);
if ($file && str_starts_with($file, $root) && is_file($file)) {
return false;
}
// Redirect root to /demo/
if ($uri === '/' || $uri === '') {
require $root . '/demo/index.html';
return true;
}
// Optional: Make demo files accessible without /demo
$demoFile = realpath($root . '/demo' . $uri);
if ($demoFile && str_starts_with($demoFile, $root . '/demo') && is_file($demoFile)) {
return false;
}
// Fallback
http_response_code(404);
echo 'Not found';