Skip to content

Redirect item links to the item's current URL when it moved projects - #385

Merged
Cannonb4ll merged 1 commit into
ploi:mainfrom
sandervanhooft:claude/item-links-board-moves-cf9cae
Oct 15, 2026
Merged

Cannonb4ll merged 1 commit into
ploi:mainfrom
sandervanhooft:claude/item-links-board-moves-cf9cae

Conversation

@sandervanhooft

Copy link
Copy Markdown
Contributor

When an item is moved to another project, its old link (e.g. /projects/1-general/items/5-coupons) returns a 404 because the item is only looked up inside the project from the URL.

This adds a fallback in ItemController::findItem():

  1. Look the item up in the requested project (unchanged).
  2. If it isn't there, look it up by slug across all projects.
  3. If the slug doesn't match either (e.g. it was edited), use the ID the slug starts with (5 in 5-coupons).

When the resolved item's current URL differs from the requested one, the request is redirected to view_url (or markdown_url for .md URLs). The fallback uses Item::visibleForCurrentUser(), so private items and items in private projects still return a 404.

Open question: 302 or 301?

The redirect currently uses Laravel's default 302. A 301 is better for SEO, but browsers cache 301s indefinitely: if an item is moved from project A to B and later back to A, a cached A→B redirect plus the live B→A redirect would send visitors in a loop. I've left it at 302. Happy to switch to 301 if you prefer that trade-off.

Tests

  • Moved item redirects to its new project URL (HTML and .md)
  • Outdated slug resolves via the item ID (project and project-less URLs)
  • Unknown project + slug returns 404
  • Private item is not reachable through the ID fallback

When an item is not found in the requested project, fall back to looking it up by slug, then by the ID its slug starts with, and redirect to its current URL. Applies to both the HTML and .md item URLs.
@Cannonb4ll

Copy link
Copy Markdown
Member

I agree with the 302 to be honest here.

@Cannonb4ll
Cannonb4ll merged commit ba57613 into ploi:main Oct 15, 2026
3 checks passed
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 this pull request may close these issues.

2 participants