ghwikipp: Strip off empty '/' chars from the end of PHP_SELF and redirect.

From a874e1d9acc748e751541b91a2f056d99f3b10b1 Mon Sep 17 00:00:00 2001
From: "Ryan C. Gordon" <[EMAIL REDACTED]>
Date: Sat, 18 Jun 2022 00:14:44 -0400
Subject: [PATCH] Strip off empty '/' chars from the end of PHP_SELF and
 redirect.

Otherwise a link on wiki.libsdl.org/x/ to 'y' will go to
wiki.libsdl.org/x/y instead of wiki.libsdl.org/y
---
 index.php | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/index.php b/index.php
index 05d4b08..e62b899 100644
--- a/index.php
+++ b/index.php
@@ -1024,6 +1024,14 @@ function build_index($base, $dname, &$output)
 
 // Main line!
 
+// can't have a '/' at the end of the URL or we'll generate incorrect links.
+$stripped_url = preg_replace('/\/+$/', '', $_SERVER['PHP_SELF'], -1, $count);
+if ($count && ($stripped_url != '')) {
+    redirect($stripped_url);
+}
+unset($count);
+unset($stripped_url);
+
 $reqargs = explode('/', preg_replace('/^\/?(.*?)\/?$/', '$1', $_SERVER['PHP_SELF']));
 $reqargcount = count($reqargs);