@@ -457,20 +457,6 @@ protected function checkRoutes(string $uri): bool
457457
458458 // Does the RegEx match?
459459 if (preg_match ('#^ ' . $ routeKey . '$#u ' , $ uri , $ matches )) {
460- // Is this route supposed to redirect to another?
461- if ($ this ->collection ->isRedirect ($ routeKey )) {
462- // replacing matched route groups with references: post/([0-9]+) -> post/$1
463- $ redirectTo = preg_replace_callback ('/(\([^\(]+\))/ ' , static function (): string {
464- static $ i = 1 ;
465-
466- return '$ ' . $ i ++;
467- }, is_array ($ handler ) ? key ($ handler ) : $ handler );
468-
469- throw new RedirectException (
470- preg_replace ('#\A ' . $ routeKey . '\z#u ' , $ redirectTo , $ uri ),
471- $ this ->collection ->getRedirectCode ($ routeKey ),
472- );
473- }
474460 // Store our locale so CodeIgniter object can
475461 // assign it to the Request.
476462 if (str_contains ($ matchedKey , '{locale} ' )) {
@@ -491,6 +477,25 @@ protected function checkRoutes(string $uri): bool
491477 unset($ matched );
492478 }
493479
480+ // Is this route supposed to redirect to another?
481+ if ($ this ->collection ->isRedirect ($ matchedKey )) {
482+ // replacing matched route groups with references: post/([0-9]+) -> post/$1
483+ $ redirectTo = preg_replace_callback ('/(\([^\(]+\))/ ' , static function (): string {
484+ static $ i = 1 ;
485+
486+ return '$ ' . $ i ++;
487+ }, is_array ($ handler ) ? key ($ handler ) : $ handler );
488+
489+ if (str_contains ($ matchedKey , '{locale} ' )) {
490+ $ redirectTo = str_replace ('{locale} ' , $ this ->detectedLocale , $ redirectTo );
491+ }
492+
493+ throw new RedirectException (
494+ preg_replace ('#\A ' . $ routeKey . '\z#u ' , $ redirectTo , $ uri ),
495+ $ this ->collection ->getRedirectCode ($ matchedKey ),
496+ );
497+ }
498+
494499 // Are we using Closures? If so, then we need
495500 // to collect the params into an array
496501 // so it can be passed to the controller method later.
0 commit comments