Skip to content

Commit 5d91085

Browse files
committed
Appending '/' to URL if directory to prevent complications with links
1 parent 9840bdc commit 5d91085

File tree

1 file changed

+4
-7
lines changed

1 file changed

+4
-7
lines changed

index.php

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,14 +182,11 @@ function respondWithFile($file, $isAlreadyNotFound=false, $isInsideStatics=false
182182
}
183183

184184
// if path is directory search inside directory
185-
$add = 0;
186185
if(is_dir($file)){
186+
if(empty($file) || $file[-1] !== '/'){ header('Location: '.FULL_REQUEST.'/', true); exit(0); }
187187
$notFound = true;
188-
$needSlash = (empty($file) || $file[-1] !== '/');
189-
$add += ($needSlash && !$isAlreadyNotFound);
190-
$dir = $file.($needSlash ? '/' : '');
191188
foreach(DEFAULT_INDEX_FILES as $indexName){
192-
$path = $dir.$indexName;
189+
$path = $file.$indexName;
193190
if(file_exists($path)){
194191
$file = $path;
195192
$notFound = false;
@@ -205,8 +202,8 @@ function respondWithFile($file, $isAlreadyNotFound=false, $isInsideStatics=false
205202
// execute PHP files
206203
if(str_ends_with($file, '.php')){
207204
// load language files, define constants and include config
208-
define('ROOT_DEPTH', substr_count(FULL_REQUEST, "/")+$add);
209-
define('BASE_DEPTH', substr_count(REQUEST, "/")+$add);
205+
define('ROOT_DEPTH', substr_count(FULL_REQUEST, "/"));
206+
define('BASE_DEPTH', substr_count(REQUEST, "/"));
210207
define('BASE', str_repeat('../', BASE_DEPTH));
211208
define('ROOT', BASE.(ROOT_DEPTH != BASE_DEPTH ? '../' : ''));
212209
foreach(scandir(STATICS) as $dir) if(is_dir(STATICS.$dir)) define(strtoupper($dir), ROOT.$dir.'/');

0 commit comments

Comments
 (0)