diff --git a/extension/Classes/Core/Helper/OnString.php b/extension/Classes/Core/Helper/OnString.php
index de4bbe91955864972fef1ebd29a4c35dd7ddd211..3b8cf6f3628a4c3d0f18fae97ed1b003fa696e85 100644
--- a/extension/Classes/Core/Helper/OnString.php
+++ b/extension/Classes/Core/Helper/OnString.php
@@ -669,5 +669,43 @@ class OnString {
         }
         return $value;
     }
+
+
+    /*
+     * Check the given $url for ending with a index.php or a query or an anker.
+     * If one of them found: remove it.
+     * Return cleaned $url
+     */
+    public static function urlStripFile($url) {
+
+        if ($url == '') {
+            return '';
+        }
+
+        // Take care all %dd are replaced by real characters
+        $url = urldecode($url);
+
+        // Explode to examine last part
+        $arr = explode('/', $url);
+
+        $last = count($arr) - 1;
+
+        if ($arr[$last] == '') {
+            unset($arr[$last]);
+            $last--;
+        }
+
+        if ($last < 1) {
+            return $url;
+        }
+
+        // Last component starts with 'index.php' or contains a '?' or '#' - that's likely not to be a part of baserurl
+        if (0 == strcmp('index.php', substr($arr[$last], 0, 9)) ||
+            strpos($arr[$last], '?') !== false || strpos($arr[$last], '#') !== false) {
+            unset($arr[$last]);
+        }
+
+        return implode('/', $arr);
+    }
 }
 
diff --git a/extension/Classes/Core/Store/Config.php b/extension/Classes/Core/Store/Config.php
index ee5127d9798d2e5c7e01ca6d7c55aa4f635d5386..edf19b7e9b758c03a488922e9a6d9900bf434240 100644
--- a/extension/Classes/Core/Store/Config.php
+++ b/extension/Classes/Core/Store/Config.php
@@ -15,6 +15,7 @@ use IMATHUZH\Qfq\Core\Helper\OnArray;
 use IMATHUZH\Qfq\Core\Helper\OnString;
 use IMATHUZH\Qfq\Core\Helper\Path;
 use IMATHUZH\Qfq\Core\Helper\Support;
+use IMATHUZH\Qfq\Core\Typo3\T3Handler;
 
 /**
  * Class Config
@@ -98,6 +99,14 @@ class Config {
             $config = array_merge($configT3qfq, $config);
         }
 
+        // Set default from baseUrl if not given
+        if ($config[SYSTEM_BASE_URL] === '') {
+
+            $config[SYSTEM_BASE_URL] = OnString::urlStripFile($_SERVER["SCRIPT_URI"]);
+
+            T3Handler::updateT3QfqConfig(SYSTEM_BASE_URL, $config[SYSTEM_BASE_URL]); // Legacy behaviour.
+        }
+
         $config = self::renameConfigElements($config);
         $config = self::setDefaults($config);
         self::checkDeprecated($config);
diff --git a/extension/Tests/Unit/Core/Helper/OnStringTest.php b/extension/Tests/Unit/Core/Helper/OnStringTest.php
index efb36fbb4074c78ff7e0e21a3d0563c761fc9d1c..64d3847cb524a357b4b3acc22a9758b7be16d89f 100644
--- a/extension/Tests/Unit/Core/Helper/OnStringTest.php
+++ b/extension/Tests/Unit/Core/Helper/OnStringTest.php
@@ -295,4 +295,25 @@ class OnStringTest extends TestCase {
         $this->assertEquals('SELECT', OnString::removeLeadingBrace("  (  (  SELECT"));
 
     }
+
+    public function testUrlStripFile() {
+        $this->assertEquals('', OnString::urlStripFile(""));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com"));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/index.php"));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/index.php?id=100"));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/?id=100"));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/#new"));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/help#new"));
+        $this->assertEquals('www.example.com', OnString::urlStripFile("www.example.com/index.php?help#new"));
+
+        $this->assertEquals('http://www.example.com', OnString::urlStripFile("http://www.example.com/help#new"));
+        $this->assertEquals('http://www.example.com:9090', OnString::urlStripFile("http://www.example.com:9090/help#new"));
+
+        $this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub"));
+        $this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/"));
+        $this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/?id=1"));
+        $this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/index.php"));
+        $this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/index.php?id=1"));
+        $this->assertEquals('www.example.com/help/sub', OnString::urlStripFile("www.example.com/help/sub/index.php?id=1#freak"));
+    }
 }
\ No newline at end of file