diff --git a/typo3/sysext/core/Classes/Routing/PageRouter.php b/typo3/sysext/core/Classes/Routing/PageRouter.php
index 4f70dfc2cf640a6545c7662044ae109016f1db13..b89eb4be7654bc156a36941e1766d8f4e906e5b7 100644
--- a/typo3/sysext/core/Classes/Routing/PageRouter.php
+++ b/typo3/sysext/core/Classes/Routing/PageRouter.php
@@ -147,7 +147,7 @@ class PageRouter implements RouterInterface
             if ($normalizedParams instanceof NormalizedParams) {
                 $scriptName = ltrim($normalizedParams->getScriptName(), '/');
                 if ($scriptName !== '' && strpos($urlPath, $scriptName) !== false) {
-                    $urlPath = str_replace($scriptName, '', $urlPath);
+                    $urlPath = str_replace('/' . $scriptName, '', $urlPath);
                 }
             }
         }
diff --git a/typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/PageTypeDecoratorTest.php b/typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/PageTypeDecoratorTest.php
index 3c2f1cd76d1794479321e98e6dd2173930478966..2c4b6fa883ddcdbcfc80113fc51dcd5aaa777548 100644
--- a/typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/PageTypeDecoratorTest.php
+++ b/typo3/sysext/frontend/Tests/Functional/SiteHandling/EnhancerSiteRequest/PageTypeDecoratorTest.php
@@ -94,11 +94,17 @@ class PageTypeDecoratorTest extends AbstractEnhancerSiteRequestTest
                         )
                     )
             ;
+
             $testSets = array_merge(
                 $testSets,
-                [$testSetForPageContainingIndexInSlug->describe() => [$testSetForPageContainingIndexInSlug]]
+                [
+                    $testSetForPageContainingIndexInSlug->describe() => [
+                        $testSetForPageContainingIndexInSlug,
+                    ],
+                ],
             );
         }
+
         return $testSets;
     }
 
diff --git a/typo3/sysext/frontend/Tests/Functional/SiteHandling/Framework/Builder/Builder.php b/typo3/sysext/frontend/Tests/Functional/SiteHandling/Framework/Builder/Builder.php
index 05daa95b18d35a7f318a1d6e5d8b588f74ed0edb..8c3ad7b7d37d082da5d36c88ac916b3656628e49 100644
--- a/typo3/sysext/frontend/Tests/Functional/SiteHandling/Framework/Builder/Builder.php
+++ b/typo3/sysext/frontend/Tests/Functional/SiteHandling/Framework/Builder/Builder.php
@@ -126,6 +126,16 @@ class Builder
                 'menu.json' => 10,
             ],
         ];
+        $multipleTypesConfigurationDotPhp = [
+            'type' => 'PageType',
+            'default' => '.php',
+            'index' => 'index',
+            'map' => [
+                '.php' =>  0,
+                'menu.json' =>  10,
+                '.xml' => 20
+            ],
+        ];
 
         return [
             PageTypeDeclaration::create('null ".html"')
@@ -156,6 +166,15 @@ class Builder
                 ->withGenerateParameters(['&type=0'])
                 ->withResolveArguments(['pageType' => 0])
                 ->withVariables(Variables::create(['pathSuffix' => '/', 'index' => ''])),
+            PageTypeDeclaration::create('null ".php"')
+                ->withConfiguration($multipleTypesConfigurationDotPhp)
+                ->withResolveArguments(['pageType' => 0])
+                ->withVariables(Variables::create(['pathSuffix' => '.php', 'index' => 'index'])),
+            PageTypeDeclaration::create('0 ".php"')
+                ->withConfiguration($multipleTypesConfigurationDotPhp)
+                ->withGenerateParameters(['&type=0'])
+                ->withResolveArguments(['pageType' => 0])
+                ->withVariables(Variables::create(['pathSuffix' => '.php', 'index' => 'index'])),
         ];
     }