Skip to content

Commit 7032d2e

Browse files
author
jpmoormann
committed
handle trailing slashes in URI
1 parent e3b4171 commit 7032d2e

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

index.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ function eh($e,$s=0,$f=0,$l=0) { ob_clean(); echo '<pre><h1>An error occurred</h
77
$config = json_decode(file_get_contents('config.json'),false, 10, JSON_THROW_ON_ERROR);
88
if($config->maintenance) { http_response_code(503); exit; }
99
date_default_timezone_set($config->timezone ?? 'America/New_York');
10-
$req = (object)parse_url($_SERVER['REQUEST_URI'] ?? '/');
11-
if(property_exists($req,'query')) parse_str($req->query, $req->query);
10+
$req = (object)parse_url(rtrim($_SERVER['REQUEST_URI'],'/') ?: '/');
11+
if(property_exists($req,'query')) parse_str($req->query, $req->query); else $req->query = [];
1212
$r = $config->routes->{$req->path} ?? $config->routes->{'/404'} ?? throw new Exception('Missing 404 route');
1313
ob_start();
1414
if(property_exists($r,'page')) file_exists($r->page) ? include $r->page : throw new Exception('Missing page file');

0 commit comments

Comments
 (0)