@@ -42,13 +42,16 @@ private function detectBasePath(string $basePath): string
42
42
return $ basePath ;
43
43
}
44
44
if (isset ($ _SERVER ['PATH_INFO ' ])) {
45
- $ fullPath = array_shift ( explode ('? ' ,$ _SERVER ['REQUEST_URI ' ])) ;
45
+ $ fullPath = explode ('? ' , $ _SERVER ['REQUEST_URI ' ])[ 0 ] ;
46
46
$ path = $ _SERVER ['PATH_INFO ' ];
47
- if (substr ($ fullPath , -1 *strlen ($ path )) == $ path ) {
48
- return substr ($ fullPath , 0 , -1 *strlen ($ path ));
47
+ if (!$ path ) {
48
+ return $ _SERVER ['PHP_SELF ' ];
49
+ }
50
+ if (substr ($ fullPath , -1 * strlen ($ path )) == $ path ) {
51
+ return substr ($ fullPath , 0 , -1 * strlen ($ path ));
49
52
}
50
53
}
51
- return '' ;
54
+ return '/ ' ;
52
55
}
53
56
54
57
private function loadPathTree (): PathTree
@@ -102,15 +105,10 @@ private function getRouteNumbers(ServerRequestInterface $request): array
102
105
103
106
private function removeBasePath (ServerRequestInterface $ request ): ServerRequestInterface
104
107
{
105
- if ($ this ->basePath ) {
106
- $ path = $ request ->getUri ()->getPath ();
107
- $ basePath = rtrim ($ this ->basePath , '/ ' );
108
- if (substr ($ path , 0 , strlen ($ basePath )) == $ basePath ) {
109
- $ path = substr ($ path , strlen ($ basePath ));
110
- $ request = $ request ->withUri ($ request ->getUri ()->withPath ($ path ));
111
- }
112
- } elseif (isset ($ _SERVER ['PATH_INFO ' ])) {
113
- $ path = $ _SERVER ['PATH_INFO ' ];
108
+ $ path = $ request ->getUri ()->getPath ();
109
+ $ basePath = rtrim ($ this ->basePath , '/ ' );
110
+ if (substr ($ path , 0 , strlen ($ basePath )) == $ basePath ) {
111
+ $ path = substr ($ path , strlen ($ basePath ));
114
112
$ request = $ request ->withUri ($ request ->getUri ()->withPath ($ path ));
115
113
}
116
114
return $ request ;
0 commit comments