ghwikipp: Redirect from "subdir" to "subdir/FrontPage"

From c38b5247169c94b0be0e17adcaab59656fab9f14 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Mon, 20 Jun 2022 10:46:50 -0400
Subject: [PATCH] Redirect from "subdir" to "subdir/FrontPage"

This fixes relative links on the page going to the parent directory
instead of the subdir.
---
 index.php | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/index.php b/index.php
index e62b899..6f136fc 100644
--- a/index.php
+++ b/index.php
@@ -1030,7 +1030,6 @@ function build_index($base, $dname, &$output)
     redirect($stripped_url);
 }
 unset($count);
-unset($stripped_url);
 
 $reqargs = explode('/', preg_replace('/^\/?(.*?)\/?$/', '$1', $_SERVER['PHP_SELF']));
 $reqargcount = count($reqargs);
@@ -1063,9 +1062,9 @@ function build_index($base, $dname, &$output)
     if ($drop_args > 0) {
         $reqargcount -= $drop_args;
         if ($reqargcount == 0) {
-            $document .= '/FrontPage';  // each subdir gets a default FrontPage.
-            $reqargs = array( $document );
-            $drop_args = 0;
+            // each subdir gets a default FrontPage. Redirect to it so there's
+            // no confusion about relative URLs on the page going to the right subdir.
+            redirect("$stripped_url/FrontPage");
         } else {
             while ($drop_args > 0) {
                 array_shift($reqargs);  // drop subdirs from $reqargs