-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathdev-routing.php
45 lines (33 loc) · 1.06 KB
/
dev-routing.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
40
41
42
43
44
45
<?php
declare(strict_types=1);
/**
* I actually learned something about php's internal server with this file.
* If you return false for a file that exists, php will default to
* resolve it an return it.
*/
$root = $_SERVER['DOCUMENT_ROOT'];
$path = '/'.ltrim(parse_url(urldecode($_SERVER['REQUEST_URI']))['path'], '/');
if (file_exists($root.$path)) {
// Enforces trailing slash, keeping links tidy in the admin
if (is_dir($root.$path)
&& substr($path, -1) !== '/') {
header("Location: $path/");
exit;
}
// Runs PHP file if it exists
if (strpos($path, '.php') !== false) {
chdir(dirname($root.$path));
if (false === include $root.$path) {
/** @noinspection ForgottenDebugOutputInspection */
error_log('Failed including file :: '.$root.$path.PHP_EOL);
exit(1);
}
return true;
}
if (0 === strpos($path, '/wp-admin')) {
return false;
}
}
// Otherwise, run `index.php`
chdir($root);
require_once __DIR__.DIRECTORY_SEPARATOR.'index.php';