3 * Forwarder/Router to doku.php
5 * In normal usage, this script simply redirects to doku.php. However it can also be used as a routing
6 * script with PHP's builtin webserver. It takes care of .htaccess compatible rewriting, directory/file
7 * access permission checking and passing on static files.
11 * php -S localhost:8000 index.php
13 * @license GPL 2 (http://www.gnu.org/licenses/gpl.html)
14 * @author Andreas Gohr <andi@splitbrain.org>
16 if (php_sapi_name() != 'cli-server') {
17 if (!defined('DOKU_INC')) define('DOKU_INC', dirname(__FILE__
) . '/');
18 require_once(DOKU_INC
. 'inc/init.php');
20 send_redirect(DOKU_URL
. 'doku.php');
23 // ROUTER starts below
25 // avoid path traversal
26 $_SERVER['SCRIPT_NAME'] = str_replace('/../', '/', $_SERVER['SCRIPT_NAME']);
28 // routing aka. rewriting
29 if (preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
31 $_GET['media'] = $m[1];
32 require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/fetch.php';
34 } elseif (preg_match('/^\/_detail\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
36 $_GET['media'] = $m[1];
37 require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/detail.php';
39 } elseif (preg_match('/^\/_export\/([^\/]+)\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
41 $_GET['do'] = 'export_' . $m[1];
43 require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
46 $_SERVER['SCRIPT_NAME'] !== '/index.php' &&
47 file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'])
51 // access limitiations
52 if (preg_match('/\/([._]ht|README$|VERSION$|COPYING$)/', $_SERVER['SCRIPT_NAME']) or
53 preg_match('/^\/(data|conf|bin|inc)\//', $_SERVER['SCRIPT_NAME'])
55 header('HTTP/1.1 403 Forbidden');
59 if (substr($_SERVER['SCRIPT_NAME'], -4) == '.php') {
61 require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
67 // treat everything else as a potential wiki page
68 // working around https://bugs.php.net/bug.php?id=61286
69 $request_path = preg_split('/\?/', $_SERVER['REQUEST_URI'], 2)[0];
70 if (isset($_SERVER['PATH_INFO'])) {
71 $_GET['id'] = $_SERVER['PATH_INFO'];
72 } elseif ($request_path != '/' && $request_path != '/index.php') {
73 $_GET['id'] = $_SERVER['SCRIPT_NAME'];
76 require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';