diff --git a/core/tests/UrlsTest.php b/core/tests/UrlsTest.php index 4f766ef9..a9ab2268 100644 --- a/core/tests/UrlsTest.php +++ b/core/tests/UrlsTest.php @@ -128,6 +128,20 @@ class UrlsTest extends TestCase 'http://$SERVER/$INSTALL_DIR/index.php?q=$PATH should return $PATH' ); + // even when we are /test/... publicly, and generating /test/... URLs, + // we should still be able to handle URLs at the root because that's + // what apache sends us when it is reverse-proxying a subdirectory + $this->assertEquals( + "tasty/cake", + _get_query("/tasty/cake"), + 'http://$SERVER/$INSTALL_DIR/$PATH should return $PATH' + ); + $this->assertEquals( + "tasty/cake", + _get_query("/index.php?q=tasty/cake"), + 'http://$SERVER/$INSTALL_DIR/index.php?q=$PATH should return $PATH' + ); + $this->assertEquals( "tasty/cake%20pie", _get_query("/test/index.php?q=tasty/cake%20pie"), diff --git a/core/urls.php b/core/urls.php index 4482f387..8208dd5b 100644 --- a/core/urls.php +++ b/core/urls.php @@ -121,7 +121,7 @@ function _get_query(?string $uri = null): string // if we're looking at http://site.com/$INSTALL_DIR/$PAGE, // then get the query from the path else { - $base = get_base_href() . "/"; + $base = get_base_href(); $q = $parsed_url["path"] ?? ""; // sometimes our public URL is /img/foo/bar but after @@ -130,6 +130,10 @@ function _get_query(?string $uri = null): string if (str_starts_with($q, $base)) { $q = substr($q, strlen($base)); } + + // whether we are /img/foo/bar or /foo/bar, we still + // want to remove the leading slash + $q = ltrim($q, "/"); } assert(!str_starts_with($q, "/"));