Skip to content

Commit 3250d15

Browse files
authored
Merge pull request #308 from WebFiori/dev
fix(routing): preserve query string on redirect and fix root sub-route crash
2 parents fd44360 + 007c799 commit 3250d15

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

WebFiori/Framework/Router/Router.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,10 @@ public static function redirect(string $path, string $to, int $code = 301) {
607607
if (!in_array($httpCode, $allowedCodes)) {
608608
$httpCode = 301;
609609
}
610+
$requestedUri = Router::getRouteUri()->getRequestedUri();
611+
if ($requestedUri !== null && strlen($requestedUri->getQueryString()) > 0) {
612+
$to .= '?'.$requestedUri->getQueryString();
613+
}
610614
App::getResponse()->addHeader('location', $to);
611615
App::getResponse()->setCode($httpCode);
612616

@@ -1104,7 +1108,7 @@ private function fixFilePath($path) {
11041108
private function fixUriPath(string $path): string {
11051109
if (strlen($path) != 0 && $path != '/') {
11061110
if ($path[strlen($path) - 1] == '/' || $path[0] == '/') {
1107-
while ($path[0] == '/' || $path[strlen($path) - 1] == '/') {
1111+
while (strlen($path) > 0 && ($path[0] == '/' || $path[strlen($path) - 1] == '/')) {
11081112
$path = trim($path, '/');
11091113
}
11101114
$path = '/'.$path;

0 commit comments

Comments
 (0)