-
Notifications
You must be signed in to change notification settings - Fork 345
/
run.php
42 lines (34 loc) · 1.2 KB
/
run.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
<?php
declare(strict_types=1);
// Only run this if running from PHP embedded server.
if (PHP_SAPI === 'cli-server') {
$path = parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH) ?: '';
if (preg_match('/\.(?:js|ico|gif|jpg|png|css|asc|txt|svg)$/', $path)) {
// Serves customization.
if (preg_match('/^\/user\.(js|css)$/', $path)) {
return false;
}
// Serves frontend.
if (preg_match('/^\/public/', $path)) {
return false;
}
// Serves favicons and thumbnails.
if (preg_match('/^\/data/', $path)) {
return false;
}
// The rewrite rules do not match real servers perfectly –
// Apache would use an internal redirect instead of HTTP one.
// Redirects to proper location for images.
if (preg_match('/\/(favicons|thumbnails)/', $path)) {
header('Location: /data' . $path);
exit;
}
// Redirects to proper location for frontend.
header('Location: /public' . $path);
exit;
} else {
// taken from cli arg, hack for updater
$_SERVER['SERVER_ADDR'] = $_SERVER['SERVER_NAME'];
require 'index.php';
}
}