-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrouter.php
More file actions
80 lines (70 loc) · 2.22 KB
/
Copy pathrouter.php
File metadata and controls
80 lines (70 loc) · 2.22 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* MotorsportDB - Development Server Router
* Handles clean URLs for PHP built-in server
*
* Usage: php -S localhost:8080 router.php
*/
$uri = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH);
$query = parse_url($_SERVER['REQUEST_URI'], PHP_URL_QUERY);
// Sitemap
if ($uri === '/sitemap.xml') {
require __DIR__ . '/sitemap-serve.php';
return true;
}
// Map clean URLs to PHP files
$routes = [
'/driver' => '/driver.php',
'/team' => '/team.php',
'/race' => '/race.php',
'/head-to-head' => '/head-to-head.php',
];
// Check if it's a clean URL
if (isset($routes[$uri])) {
$_SERVER['SCRIPT_NAME'] = $routes[$uri];
$_GET = [];
if ($query) {
parse_str($query, $_GET);
}
require __DIR__ . $routes[$uri];
return true;
}
// Handle /games/ paths - map to public/games/
$gameRoutes = [
'/games/driverdle.php' => 'driverdle',
'/games/driverdle' => 'driverdle',
'/games/driverdle-f1.php' => 'driverdle-f1',
'/games/driverdle-f1' => 'driverdle-f1',
'/games/driverdle-all.php' => 'driverdle-all',
'/games/driverdle-all' => 'driverdle-all',
'/games/driverdle-classic.php' => 'driverdle-classic',
'/games/driverdle-classic' => 'driverdle-classic',
'/games/guess-who.php' => 'guess-who',
'/games/guess-who' => 'guess-who',
];
if (isset($gameRoutes[$uri])) {
$gamePath = __DIR__ . '/public/games/' . $gameRoutes[$uri] . '.php';
if (file_exists($gamePath)) {
require $gamePath;
return true;
}
}
// Fallback: generic /games/ regex handler
if (preg_match('#^/games/(.+)$#', $uri, $matches)) {
$game = preg_replace('/\.php$/', '', $matches[1]);
$gamePath = __DIR__ . '/public/games/' . $game . '.php';
if (file_exists($gamePath)) {
require $gamePath;
return true;
}
}
// Serve static files and existing PHP files normally
if (file_exists(__DIR__ . $uri)) {
return false; // Let PHP serve the file
}
// For other requests, try to route through public/
if (preg_match('/\.(css|js|png|jpg|jpeg|gif|svg|woff|woff2|ttf|json|ico)$/i', $uri)) {
return false;
}
// Default: return false to let PHP handle it
return false;