Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] 404 when trying to "Add as redirect" in "Failures" #307

Closed
ieteo opened this issue Sep 1, 2022 · 3 comments · Fixed by #308
Closed

[BUG] 404 when trying to "Add as redirect" in "Failures" #307

ieteo opened this issue Sep 1, 2022 · 3 comments · Fixed by #308

Comments

@ieteo
Copy link
Contributor

ieteo commented Sep 1, 2022

Describe the bug

The release 4.2.0 fixed the bug #300 when editing or removing path containing slashes from "Routes". Thank you!

However, the bug is still present when trying to "Add as redirect" from "Failures", which results in 404 error as described in #300

This bug is only present on Apache when the AllowEncodedSlashes is set to Off

Steps to reproduce

  1. Get the Kirby starter kit and instal distantnative/retour-for-kirby
git clone https://github.com/getkirby/starterkit.git
cd starterkit
composer require distantnative/retour-for-kirby
  1. Create Dockerfile with following content
FROM php:8.1-apache
RUN a2enmod rewrite
  1. Build image and run the container
docker build -t starterkit .
docker run -p 80:80 -v "$PWD":/var/www/html starterkit
  1. Call a non-existent URL containing slashes e.g. http://localhost/sub/not-existing
  2. Go to http://localhost/panel, create user and log in
  3. Go to Rredirect > Failures and Add as redirect the previously called non-existent URL

Result:
404 Not Found from Apache

Note
Removing path containing slashes under Failures also results in 404 error

Expected behavior

modal opens up in order to add the path as redirect

Context

  • Kirby version: 3.7.5
  • Retour version: 4.2.0
  • Web Server: Apache with AllowEncodedSlashes Off
@distantnative
Copy link
Owner

🙈

@ieteo
Copy link
Contributor Author

ieteo commented Sep 1, 2022

I assume that changing this line:

const path = encodeURIComponent(row.path);

to:
const path = encodeURIComponent(row.path.replace(/\//g, "\x1D"));

as what was done in:

const id = encodeURIComponent(row.from.replace(/\//g, "\x1D"));

would hopefully also fix it in FailuresTab

EDIT:

The above alone won fix the issue.

In order to fix it, I had to changed the above and also change this line:

'from' => urldecode($path)

to:
'from' => str_replace("\x1D",'/', urldecode($path))

@distantnative
Copy link
Owner

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants