nystudio107 / craft-retour

Retour allows you to intelligently redirect legacy URLs, so that you don't lose SEO value when rebuilding & restructuring a website
https://nystudio107.com/plugins/retour
Other
39 stars 26 forks source link

Short links not redirecting on website: HTTP 404 / Template not found #270

Closed localhorst closed 1 year ago

localhorst commented 1 year ago

Describe the bug

Short links not working on website, Craft 4.3.3. I get a 404 error when calling the short link url. Redirects are working correctly.

To reproduce

  1. Install retour plugin 4.1.9
  2. Create a shortLink field in the field manager
  3. Add short link to a tab in section field layout (Match Path only)
  4. Fill in short link string "foobar", "/foobar" or "/foobar/" on one of the entries, save.
  5. Call https://myproject.com/foobar in the frontend: HTTP 404 – Not Found – yii\web\NotFoundHttpException Template not found: foobar
  6. Check retour > short links in controlpanel: List is empty

Expected behaviour

  1. I expect to be redirected to the page when calling the short link foobar
  2. A list of short links in the controlpanel module.

Versions

(Edited again, I thought I had one successful redirect when using two slashes, but it was a fluke. Sorry :). )

khalwat commented 1 year ago

I'm unable to reproduce.

  1. Create a Short Link field, add it to the field layout of my Blog channel, enter foobar
Screenshot 2023-02-10 at 10 04 30 AM
  1. Go to the frontend, and enter the URL with /foobar after it:
Screenshot 2023-02-10 at 10 04 58 AM
  1. It properly redirects to the blog entry:
Screenshot 2023-02-10 at 10 05 02 AM

So something else must be going on here.

Perhaps your site is multi-site, and you didn't set the field to be enabled for all of the sites?

Perhaps some kind of Ngnix or other server config is interfering here?

The fact that the short link apparently isn't even saved makes me think something very strange is going on here... have your checked your web.log for any errors?

Will re-open if I can be given a way to reproduce this issue.

localhorst commented 1 year ago

I managed to get it working. I guess it was related to a missing 404 configuration and active logins into the backend / control panel. So if you run into this problem, make sure to get your 404 page running and also test your shortlinks in a browser without an active control panel session.

khalwat commented 1 year ago

FWIW, I did have an active session in the CP when I did my tests above.

FrDH commented 1 year ago

I have the exact same issue, but with a Craft 3 installation (retour 3.2.7). Most of the time the "short link" list was empty (like OP mentioned), sometimes the short like was created, but it would redirect from "/" to "/". After changing these values the redirect was stored as a normal redirect (not a short link).

I dug into the web.log and found some errors regarding retour:

2023-02-24 12:13:23 [-][1][-][error][nystudio107\retour\controllers\RedirectsController::actionEditRedirect] Couldn't load redirect id 139
2023-02-24 12:13:23 [-][1][-][info][application] $_GET = [
    'p' => 'beheer/retour/edit-redirect/139'
]

Any ideas?

khalwat commented 1 year ago

@FrDH what does that redirect id 139 look like in your db?

OP's problem ended up being something I couldn't reproduce, and something that ended up being solved on their end.

Try the advice that I gave them?

FrDH commented 1 year ago

It's not a multi-site, we have a functional 404 page and I was logged in when editing the page. Checking the web.log was all that was left to do.

I had a look at the DB and found:

Table information for the retour_static_redirects:

engine: InnoDB
encoding: utf8
auto_increment: 143

This is all just FYI, if it doesn't ring any bells, we'll just add the redirects manually. Thanks.

thulstrup commented 1 year ago

@khalwat I'm seeing the same issue. When I save an entry with a populated short link field, no redirect is created.

khalwat commented 1 year ago

If anyone who is having this issue can send me a db dump & your composer.json file to:

andrew@nystudio107.com

...that would be most appreciated. I'm unable to replicate this locally.

thulstrup commented 1 year ago

@khalwat I've shared a stripped down version of the website with you.

khalwat commented 1 year ago

@thulstrup How have you shared it? I'm not seeing it in my email?

khalwat commented 1 year ago

Got it now, thanks, this should be helpful!

khalwat commented 1 year ago

@thulstrup I'm unable to reproduce this with your db dump & composer.json

I've imported the db, logged in, and created an entry with a short link without issue

Is there something environmental that might be going on here?

Some questions:

a. Is there anything in logs? b. When you say "no redirect is created", do you mean in the DB? In the CP it would appear under the "short links" section. Have you validated that the created short link won't work?

thulstrup commented 1 year ago

@khalwat a) Nothing in the logs except Retour statistics cleared and Retour plugin loaded. b) I added a video showing the problem to the Dropbox I shared with you.

I did make some progress though. I discovered that short links are created for new entries just not for existing one.

khalwat commented 1 year ago

So the reason this was hard to reproduce is that it only happened on an entry that has max revisions already.

Addressed in: https://github.com/nystudio107/craft-retour/commit/020e902bf9f8b8194d0812af8ee4fcb78f5c91bf & https://github.com/nystudio107/craft-retour/commit/06f3e2884a119630dd5ee4ff0cbc66606838dcd9

Craft CMS 3:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-retour": "dev-develop as 3.2.9",

Then do a composer clear-cache && composer update

…..

Craft CMS 4:

You can try it now by setting your semver in your composer.json to look like this:

    "nystudio107/craft-retour": "dev-develop-v4 as 4.1.11",

Then do a composer clear-cache && composer update

thulstrup commented 1 year ago

I tested with Craft CMS 4 and it works 🙂 Thank you for taking the time and fixing the issue.