RedirectHandler always matches default route

Hello,

I have a very strange problem with the RedirectHandler, which I think has something to do with the default routes from the Neos.Flow package.

I am using Neos 7.2.1 (which has been updated from rather a rather old version, 3.3 I think) and the latest version of the RedirectHandler packages.

On my production server no redirect from the RedirectHandler matches.
On my development server it works correctly (even with FLOW_CONTEXT=Production).

I narrowed down the problem to the RedirectMiddleware class:

    $routingMatchResults = $request->getAttribute(ServerRequestAttributes::ROUTING_RESULTS);
    if ($routingMatchResults !== null) {
        return $next->handle($request);
    }
    $response = $this->redirectService->buildResponseIfApplicable($request);
    return $response ?? $next->handle($request);

If I understand the redirection process correctly, the RedirectService should only check for redirects from the database, if no flow route matches.

On the production server, the middleware will always match a route, which is the Neos.Flow default route.
./flow routing:list on the production server results in:

...
| 86 | {@package}/{@controller}/{@action}(.{@format})                            | any            | Neos.Flow :: default with action and format                                              |
| 87 | {@package}/{@controller}(/{@action})                                      | any            | Neos.Flow :: default                                                                     |
| 88 | {@package}                                                                | any            | Neos.Flow :: default with package                                                        |
| 89 |                                                                           | any            | Neos.Flow :: fallback                                                                    |

./flow routing:list does not list the last four routes.

So my questions are:

  • Should the Neos.Flow default routes match if a Redirect exists?
  • Should the Neos.Flow default routes even exist? And if not: How can I disable them?

If it helps:
I also tried to find more differences between the production and development server and found that the generated PackageInformationCache.php is different. It contains the same flow packages, but in different order. In both files however, the neos/flow package is before the neos/redirecthandler package.

I am really confused by this…

Regards
Leif

BTW: I also tried the workaround from the RedirectHandler documentation:

Neos:
  Flow:
    http:
      chain:
        process:
          chain:
            redirect:
              position: 'before routing'

Without success.

Since I like talking to myself (and maybe helping others with the same problem along the way), I have to add something:

I think the documentation might not be uptodate.
After looking at the Settings.yaml from the Neos.RedirectHandler package, I changed the Settings to:

Neos:
  Flow:
    http:
      middlewares:
        redirect:
          position: 'before routing'

And now it works as expected!

I still do not understand why it behaves differently on my development machine however.

Edit: I found the reason: There was a Settings.yaml on the production server in which the Neos.Flow routes where explicitly enabled:

Neos:
  Flow:
    mvc:
      routes: 
        Neos.Flow: true

After removing it, everything works as expected.
Thanks for watching and good night!

3 Likes

:grinning:

Thanks for reporting your findings that will help others with the same issue!