From 2103c612d122e7af5828c5a868faa1d78be96b0c Mon Sep 17 00:00:00 2001 From: Lee Willis Date: Wed, 23 Jul 2025 10:46:26 +0100 Subject: [PATCH 1/2] Handle redirects with a URI fragments in the destination & query args. Fixes #34 --- src/Http/Middleware/CheckForRedirects.php | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/Http/Middleware/CheckForRedirects.php b/src/Http/Middleware/CheckForRedirects.php index 54fe511..829df8f 100644 --- a/src/Http/Middleware/CheckForRedirects.php +++ b/src/Http/Middleware/CheckForRedirects.php @@ -3,6 +3,7 @@ use AltDesign\AltRedirect\Helpers\URISupport; use Symfony\Component\HttpFoundation\Response; use Illuminate\Http\Request; +use Illuminate\Support\Uri; use Closure; use Statamic\Facades\Site; @@ -77,14 +78,13 @@ private function redirectWithPreservedParams($to, $status) if (!in_array($key, $preserveKeys)) { continue; } - $filteredStrings[] = sprintf( "%s=%s", $key, $value); + $filteredStrings[$key] = $value; } - if ($filteredStrings) { - $to .= str_contains($to, '?') ? '&' : '?'; - $to .= implode('&', $filteredStrings); - } - return redirect($to , $status, config('alt-redirect.headers', [])); + $destinationUri = (new Uri($to)) + ->withQuery($filteredStrings); + + return redirect((string) $destinationUri , $status, config('alt-redirect.headers', [])); } } From 38dba9766b591265b9dac466c9e3d48872c8f44a Mon Sep 17 00:00:00 2001 From: Lee Willis Date: Tue, 24 Feb 2026 10:25:43 +0000 Subject: [PATCH 2/2] Fix incorrect merge resolution --- src/Http/Middleware/CheckForRedirects.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/Http/Middleware/CheckForRedirects.php b/src/Http/Middleware/CheckForRedirects.php index 9573719..aa7c3f4 100644 --- a/src/Http/Middleware/CheckForRedirects.php +++ b/src/Http/Middleware/CheckForRedirects.php @@ -96,10 +96,9 @@ private function redirectWithPreservedParams($to, $status) // Strip only parameters marked with strip:true, preserve all others if (!in_array($normalizedKey, $stripKeys) && !isset($seenKeys[$normalizedKey])) { $seenKeys[$normalizedKey] = true; - $filteredStrings[] = sprintf("%s=%s", urlencode($key), urlencode($value)); + $filteredStrings[$key] = $value; } } - $filteredStrings[$key] = $value; } $destinationUri = (new Uri($to))