-
Notifications
You must be signed in to change notification settings - Fork 1
/
router.php
39 lines (29 loc) · 934 Bytes
/
router.php
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
<?php
// Simple router used for the dev server AND in production.
// Get rid of .php extensions, so we can rewrite it in a different language.
$uri = $_SERVER['REQUEST_URI'];
// error_log("uri = $uri");
// get rid of query string
$path = parse_url($uri, PHP_URL_PATH);
// get rid of /picdir prefix
if (strpos($path, '/picdir') === 0) {
$path = substr($path, strlen('/picdir'));
}
// error_log("path = $path");
// /upload, /resize -> $1.php This matches the rewrite in .htaccess.
// Note: index.php is automatically mapped to /
$matches = array();
if (preg_match('/^\/([a-z_\-]+)$/', $path, $matches)) {
$name = $matches[1];
$script = "$name.php";
if (file_exists($script)) {
require $script;
exit();
}
}
error_log("[router] Not handling '$path'");
// upload.php, resize.php: NOT handled here. Dev servers falls back to its
// normal logic.
// TODO: This should serve a 404 under Apache.
return false;
?>