-$Args = '';
-$Page = preg_replace('/\?.*/', '', $_SERVER['REQUEST_URI']);
-$Page = urldecode(trim($Page, '/')) ?: 'index';
-while (TRUE) {
- if (file_exists("$Page/index.html")) {
- $Page .= '/index';
- break;
+define('DOCROOT', getcwd());
+set_include_path(implode(PATH_SEPARATOR, [ DOCROOT, __DIR__ ]));
+
+include_once 'error.inc.php';
+
+# setup requested page
+
+$request = preg_replace('/\?.*/', '', @$_SERVER['PATH_INFO'] ?: $_SERVER['REQUEST_URI']);
+$request = urldecode(trim($request, '/')) ?: 'index';
+
+$staticpage = "$request.html";
+if (file_exists($staticpage)) {
+ if (is_link($staticpage)) {
+ $target = preg_replace('/\.html$/', '', readlink($staticpage));
+ header("HTTP/1.1 302 Shorthand");
+ header("Location: $target");
+ exit;
+ }
+}
+elseif (file_exists("$request/index.html")) {
+ $staticpage = "$request/index.html";
+}
+
+require_once('article.inc.php');
+$Page = new ArchiveArticle($staticpage);
+
+# user login and control
+
+include_once 'auth.inc.php'; // sets global $User
+
+if ($Page->restricted) {
+ # access restriction
+ if (!$User->login) {
+ http_response_code(303);
+ $target = urlencode($Page->link);
+ header("Location: /login?goto=$target");
+ exit;