@@ -269,9 +269,12 @@ public static function getSiteUrl(?string $path = null, array $sapiVars = [], bo
269
269
$ sapiVars ['REQUEST_URI ' ] = $ sapiVars ['SCRIPT_NAME ' ] ?? '' ;
270
270
$ uri = static ::getCurrentString ($ sapiVars , $ cached );
271
271
$ uriParts = parse_url ($ uri );
272
- if (!empty ($ path )) {
273
- $ uriParts ['path ' ] = ($ uriParts ['path ' ] ?? '' ) . '/ ' . ltrim ($ path , '/ ' );
272
+ $ pathParts = parse_url ($ path );
273
+ if (!empty ($ pathParts ['path ' ])) {
274
+ $ uriParts ['path ' ] = ($ uriParts ['path ' ] ?? '' ) . '/ ' . ltrim ($ pathParts ['path ' ], '/ ' );
274
275
}
276
+ $ uriParts ['query ' ] = $ pathParts ['query ' ] ?? null ;
277
+ $ uriParts ['fragment ' ] = $ pathParts ['fragment ' ] ?? null ;
275
278
return static ::buildStringFromParts ($ uriParts );
276
279
}
277
280
@@ -295,24 +298,26 @@ public static function getCurrentString(array $sapiVars = [], bool $cached = fal
295
298
$ uriParts ['scheme ' ] =
296
299
$ sapiVars ['REQUEST_SCHEME ' ] ??
297
300
(!empty ($ sapiVars ['HTTPS ' ]) ? 'https ' : 'http ' );
298
- $ uriParts ['port ' ] =
299
- $ sapiVars ['HTTP_X_FORWARDED_PORT ' ] ??
300
- $ sapiVars ['SERVER_PORT ' ] ??
301
- ($ uriParts ['scheme ' ] == 'https ' ? 443 : 80 );
302
301
$ uriParts ['host ' ] =
303
302
$ sapiVars ['HTTP_X_FORWARDED_HOST ' ] ??
304
303
$ sapiVars ['HTTP_HOST ' ] ??
305
304
$ sapiVars ['SERVER_NAME ' ] ??
306
305
null ;
307
306
if (isset ($ uriParts ['host ' ]) && false !== ($ colonPos = strpos ($ uriParts ['host ' ], ': ' ))) {
308
- $ uriParts ['host ' ] = substr_replace ($ uriParts ['host ' ], '' , $ colonPos );
307
+ $ uriParts ['port ' ] = intval (substr ($ uriParts ['host ' ], $ colonPos + 1 ));
308
+ $ uriParts ['host ' ] = substr ($ uriParts ['host ' ], 0 , $ colonPos );
309
309
}
310
+ $ uriParts ['port ' ] =
311
+ $ uriParts ['port ' ] ??
312
+ $ sapiVars ['HTTP_X_FORWARDED_PORT ' ] ??
313
+ $ sapiVars ['SERVER_PORT ' ] ??
314
+ ($ uriParts ['scheme ' ] == 'https ' ? 443 : 80 );
310
315
311
316
$ uriParts ['path ' ] = $ sapiVars ['REQUEST_URI ' ] ?? null ;
312
317
if (!empty ($ sapiVars ['HTTP_X_FORWARDED_PREFIX ' ])) {
313
318
$ uriParts ['path ' ] = $ sapiVars ['HTTP_X_FORWARDED_PREFIX ' ] . '/ ' . $ uriParts ['path ' ];
314
319
}
315
- $ uriParts ['query ' ] = $ _SERVER ['QUERY_STRING ' ] ?? null ;
320
+ $ uriParts ['query ' ] = $ sapiVars ['QUERY_STRING ' ] ?? null ;
316
321
return static ::buildStringFromParts ($ uriParts );
317
322
}
318
323
0 commit comments