28 lines
908 B
PHP
Executable File
28 lines
908 B
PHP
Executable File
<?php
|
|
// Global variables
|
|
$_dr = $_SERVER['DOCUMENT_ROOT'];
|
|
|
|
// Parse path into array
|
|
// (e.g."/hello////13/thing" into ["hello", "13", "thing"])
|
|
$GLOBALS['PARSED_PATH'] = (function () {
|
|
/* - Usage of '#' as delimiters to be able to use '/' without escaping
|
|
* - (a|b) checks patterns a or b and captures it, (?:a|b) doesn't capture
|
|
*
|
|
* - (?:/|) is there to remove the first '/'
|
|
* - ([^/]+?) gets the content in a non-greedy way
|
|
* - (?:/|$) limits the capture to the next '/' or the end of the string
|
|
*/
|
|
preg_match_all('#(?:/|)([^/]+?)(?:/|$)#', $_SERVER['DOCUMENT_URI'], $matches);
|
|
|
|
// If it doesn't find anything, it is the root
|
|
$matches[1][0] = $matches[1][0] ?? '';
|
|
|
|
// We don't care about the full pattern, just the captured group
|
|
return $matches[1];
|
|
})();
|
|
|
|
match ($GLOBALS['PARSED_PATH'][0]) {
|
|
'' => include_once "$_dr/pages/index.php",
|
|
default => printf("404"),
|
|
};
|