-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
route.php
23 lines (22 loc) · 926 Bytes
/
route.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
$request = $_SERVER['REQUEST_URI'];
if (file_exists(__DIR__ . $request)) {
return false;
} else {
if (preg_match('/^\/([^\/]+)\/([^\/]+)\/([^\/]+)$/', $request, $matches)) {
$_GET['controller'] = $_REQUEST['controller'] = $matches[1];
$_GET['action'] = $_REQUEST['action'] = $matches[2];
$_GET['id'] = $_REQUEST['id'] = $matches[3];
include __DIR__ . '/index.php';
} elseif (preg_match('/^\/([^\/]+)\/([^\/]+)$/', $request, $matches)) {
$_GET['controller'] = $_REQUEST['controller'] = $matches[1];
$_GET['action'] = $_REQUEST['action'] = $matches[2];
include __DIR__ . '/index.php';
} elseif (preg_match('/^\/([^\/]+)$/', $request, $matches)) {
$_GET['controller'] = $_REQUEST['controller'] = $matches[1];
include __DIR__ . '/index.php';
} else {
header("HTTP/1.0 404 Not Found");
echo '404 Not Found';
}
}