-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
32 lines (23 loc) · 782 Bytes
/
Copy pathrouter.php
File metadata and controls
32 lines (23 loc) · 782 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
27
28
29
30
31
32
<?php
declare(strict_types=1);
// Dev router when document root is the project folder:
// php -S localhost:8000 router.php
$uri = parse_url($_SERVER['REQUEST_URI'] ?? '/', PHP_URL_PATH) ?: '/';
if (preg_match('#^/public/(.*)$#', $uri, $matches)) {
$_SERVER['SCRIPT_NAME'] = '/public/index.php';
$_SERVER['REQUEST_URI'] = '/public/' . ($matches[1] !== '' ? $matches[1] : '');
require __DIR__ . '/public/index.php';
return true;
}
if ($uri === '/public' || $uri === '/public/') {
$_SERVER['SCRIPT_NAME'] = '/public/index.php';
$_SERVER['REQUEST_URI'] = '/public/';
require __DIR__ . '/public/index.php';
return true;
}
$static = __DIR__ . $uri;
if ($uri !== '/' && is_file($static)) {
return false;
}
header('Location: /public/');
exit;