neos / redirecthandler

The Neos.RedirectHandler package for Flow
MIT License
4 stars 15 forks source link

Redirects not working #59

Closed bstrilziw closed 1 year ago

bstrilziw commented 2 years ago

Hi there,

it seems redirects don't work anymore. I haven't worked with Neos in the last few months but I guess I tried everything. The website I'm currently working on was Neos 7.1, but even after an update nothing changed.

Installed versions: neos/neos 7.3.5 neos/redirecthandler 5.0.2 neos/redirecthandler-databasestorage 5.0.2 neos/redirecthandler-neosadapter 4.3.1 neos/redirecthandler-ui 2.4.6

For testing purposes I removed every package that wasn't needed. I removed .html as defaultUriSuffix. I added the configuration from the README. I searched the Neos Slack and found others with the same problem. I created an empty Neos site (from master (so Neos 8?) like explained here.

Locally I'm using the standalone development server, in production it's Apache. In the past I had a Docker setup with nginx on my machine and nginx in production, which worked like a charm. :)

Just wanted to let you guys know that there might be a problem with some setups. Or maybe in generell? I will try my old setup with nginx later this week.

Sebobo commented 2 years ago

I cannot reproduce this issue with the same package versions you have. I used nginx and also tried with the standalone server.

dlubitz commented 2 years ago

@bstrilziw Did you check the source domain? I had an similar issue, where the redirects were created without "www." prefix, so the redirects didn't work properly if you request the url with an "www." prefix.

bstrilziw commented 2 years ago

Thank you @Sebobo and @dlubitz! :)

I checked $ ./flow routing:list and saw some strange routes at the end:

...
| 83 | {node}                                         | any | Neos.Neos :: Frontend :: Default Frontend           |
...
| 87 | {@package}/{@controller}/{@action}(.{@format}) | any | Neos.Flow :: default with action and format         |
| 88 | {@package}/{@controller}(/{@action})           | any | Neos.Flow :: default                                |
| 89 | {@package}                                     | any | Neos.Flow :: default with package                   |
| 90 |                                                | any | Neos.Flow :: fallback                               |

Those are from the Settings.yaml:

Neos:
  Flow:
    mvc:
      routes:
        'Neos.Flow': TRUE

I don't know (yet), why this configuration is there, but it breaks the redirects. I guess those routes are for Flow Controllers so you don't need to configure their routes in a Routes.yaml. I have to check with the team if this is needed.

But yes, I don't know if this is considered a bug or not. This setting will also break the redirects in my nginx environment.

Sebobo commented 2 years ago

Yes the Flow default routes can break redirects in this case. Usually they are not needed and if they are used they should be replaced by custom routes instead which also look prettier and hide your technical details.

The default setting for the redirect handler is to act after the routing middleware. So redirects only happen for non existing actions. You can also change this setting, but then the redirects are checked for every request.

Sebobo commented 2 years ago

Just realising that this is actually described in the readme 😉

https://github.com/neos/redirecthandler#what-to-do-when-redirects-are-not-triggered-but-other-controller-actions

theilm commented 2 years ago

I don't know if it's related, but redirects don't work for me either after an update to Neos 8. The reason for me was version 2.x of Guzzle. In the validateState method of the Uri the following exception is thrown:

"The path of a URI with an authority must start with a slash "/" or be empty. Automagically fixing the URI by adding a leading slash to the path is deprecated since version 1.4 and will throw an exception instead."

It is triggered because in the RedirectService $absoluteTargetUri->withPath($targetUriParts['path']); is called with a path without '/' prefix. Prefixing it like this $absoluteTargetUri->withPath('/' . $targetUriParts['path']); fixed the issue for me.

See https://github.com/neos/redirecthandler/pull/58

Sebobo commented 1 year ago

Seems to be resolved.