Merge pull request #2626 from dokuwiki-translate/lang_update_1100_1544482635
[dokuwiki.git] / index.php
blob689ce1779b6209787e4d55adbeec3bce4e4dd1af
1 <?php
2 /**
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.
9 * Usage example:
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 header("Location: doku.php");
18 exit;
21 # ROUTER starts below
23 # avoid path traversal
24 $_SERVER['SCRIPT_NAME'] = str_replace('/../', '/', $_SERVER['SCRIPT_NAME']);
26 # routing aka. rewriting
27 if(preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
28 # media dispatcher
29 $_GET['media'] = $m[1];
30 require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/fetch.php';
32 } else if(preg_match('/^\/_detail\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
33 # image detail view
34 $_GET['media'] = $m[1];
35 require $_SERVER['DOCUMENT_ROOT'] . '/lib/exe/detail.php';
37 } else if(preg_match('/^\/_media\/(.*)/', $_SERVER['SCRIPT_NAME'], $m)) {
38 # exports
39 $_GET['do'] = 'export_' . $m[1];
40 $_GET['id'] = $m[2];
41 require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
43 } elseif($_SERVER['SCRIPT_NAME'] == '/index.php') {
44 # 404s are automatically mapped to index.php
45 if(isset($_SERVER['PATH_INFO'])) {
46 $_GET['id'] = $_SERVER['PATH_INFO'];
48 require $_SERVER['DOCUMENT_ROOT'] . '/doku.php';
50 } else if(file_exists($_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'])) {
51 # existing files
53 # access limitiations
54 if(preg_match('/\/([\._]ht|README$|VERSION$|COPYING$)/', $_SERVER['SCRIPT_NAME']) or
55 preg_match('/^\/(data|conf|bin|inc)\//', $_SERVER['SCRIPT_NAME'])
56 ) {
57 die('Access denied');
60 if(substr($_SERVER['SCRIPT_NAME'], -4) == '.php') {
61 # php scripts
62 require $_SERVER['DOCUMENT_ROOT'] . $_SERVER['SCRIPT_NAME'];
63 } else {
64 # static files
65 return false;
68 # 404