mirror of
https://github.com/BookStackApp/BookStack.git
synced 2026-02-07 03:09:44 +03:00
[PR #5826] [CLOSED] feat(middleware): Page 404 to 301 | add redirect for old page slugs, caused by title change #6579
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
📋 Pull Request Information
Original PR: https://github.com/BookStackApp/BookStack/pull/5826
Author: @oopen
Created: 10/8/2025
Status: ❌ Closed
Base:
development← Head:development📝 Commits (2)
819ed7eUpdate Kernel.php380b5e0Create RedirectOldPageSlugs.php📊 Changes
2 files changed (+42 additions, -0 deletions)
View changed files
📝
app/Http/Kernel.php(+1 -0)➕
app/Http/Middleware/RedirectOldPageSlugs.php(+41 -0)📄 Description
📝 Description
This PR introduces a new Laravel middleware,
RedirectOldPageSlugs, that automatically redirects requests containing obsolete page slugs to the page’s stable permalink (/link/{id}), which then redirects to the current canonical URL.🔍 Problem
When a user changes a page’s slug in BookStack:
page_revisions).This creates a poor user experience and harms SEO.
✅ Solution
The new middleware:
webmiddleware stack (afterTrustProxies, beforePageViewCounter)./book/foo/bar→bar).page_revisions./link/{page_id}— BookStack’s built-in, stable permalink route.This approach is:
🧪 Testing
/any/book/or/chapter/path/old-slug)./link/{id}, then to the current page.📁 Files Changed
app/Http/Middleware/RedirectOldPageSlugs.php→ new middlewareapp/Http/Kernel.php→ register middleware inwebgroup⚙️ Middleware Placement
Inserted after
TrustProxiesand beforePageViewCounterto:💡 Why
/link/{id}and not the canonical URL?/link/{id}is BookStack’s official, stable permalink mechanism.✅ Benefits
page_revisions.slug).🙏 Final Note
This feature aligns with BookStack’s philosophy of usability and data integrity, and leverages existing systems (
page_revisions,/link/{id}) without introducing redundancy.Thank you for considering this contribution!
🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.