]> git.agnieray.net Git - galette.git/blobdiff - galette/includes/main.inc.php
Run Galette from a subdirectory
[galette.git] / galette / includes / main.inc.php
index f4fe96007b73e24abb460d48bbc4779869fc1bce..7f27eab445c1e01aa7bd51a34a6d958f476b81db 100644 (file)
@@ -76,6 +76,17 @@ if ($needs_update) {
     $gapp = new \Galette\Core\SlimApp();
 }
 $app = $gapp->getApp();
+$app->setBasePath((function () {
+    $scriptDir = str_replace('\\', '/', dirname($_SERVER['SCRIPT_NAME']));
+    $uri = (string)parse_url('http://a' . $_SERVER['REQUEST_URI'] ?? '', PHP_URL_PATH);
+    if (stripos($uri, $_SERVER['SCRIPT_NAME']) === 0) {
+        return dirname($_SERVER['SCRIPT_NAME']);
+    }
+    if ($scriptDir !== '/' && stripos($uri, $scriptDir) === 0) {
+        return $scriptDir;
+    }
+    return '';
+})());
 
 //CONFIGURE AND START SESSION
 
@@ -230,11 +241,6 @@ $errorHandler->registerErrorRenderer('text/html', \Galette\Renderers\Html::class
  */
 $app->add(TwigMiddleware::createFromContainer($app, Twig::class));
 
-/**
- * Trailing slash middleware
- */
-$app->add(TrailingSlash::class);
-
 $app->run();
 
 if (isset($profiler)) {