Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
branch: master
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

executable file 43 lines (32 sloc) 1.017 kb
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];

?>

Something went wrong with that request. Please try again.