/
index.php
executable file
·42 lines (32 loc) · 1017 Bytes
/
index.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
/*
** Peteris Krumins
** peteris.krumins@gmail.com
**
** A simple URL routing code, written in 2000.
*/
error_reporting(E_ALL);
# check and parse the site configuration
#
if (!file_exists('website.conf')) {
die('site configuration file was not found');
}
$SiteConfig = parse_ini_file('website.conf', true);
$parts = parse_url($_SERVER['REQUEST_URI']);
$path = preg_replace('#^/+#', '', $parts['path']); // drop slashes from the beginning of the request path
$path = preg_replace('#(//)+#', '', $path); // drop duplicate slashes
$path = preg_replace('#/+$#', '', $path); // drop trailing slashes
$path = split('/', $path);
$VConfig['request_path'] = $path;
$request_page = $VConfig['request_path'][0];
if (isset($SiteConfig['pages'][$request_page])) {
$page = $request_page;
}
else if ($request_page == '') {
$page = 'default';
}
else {
$page = 'error';
}
require_once $SiteConfig['pages'][$page];
?>