wiki: Add smart redirect to first available wiki page
What does this MR do and why?
Implements a smart 302 redirect for wiki sidebar navigation that prevents 404 errors when the "home" page doesn't exist.
Problem
When clicking the "Wiki" link in the sidebar:
- Users are always redirected to
/wikis/home - If "home" doesn't exist but other pages do, users get a 404 error
- This 404 can be intercepted by nginx/proxy, showing a generic error instead of GitLab's helpful wiki 404 page
Solution
The new behavior (controlled by wiki_smart_redirect feature flag):
| Scenario | Response |
|---|---|
| Wiki empty | 302 → /wikis/home → 200 empty state |
| Wiki has "home" page | 302 → /wikis/home → 200 shows page |
| Wiki has pages but no "home" | 302 → /wikis/first-page → 200 shows page
|
Technical changes
- Added
Wiki#first_pageandWiki#first_page_slugmethods to determine the appropriate target page - Changed route from hardcoded redirect to controller
indexaction - Added
WikiActions#indexwith feature flag check - Excluded
indexaction fromload_sidebarbefore_action (optimization - no sidebar needed for redirect) - Added comprehensive test coverage for model and controller behavior
The feature is controlled by the wiki_smart_redirect feature flag (gitlab_com_derisk type, disabled by default) to allow gradual rollout.
References
- Closes #578848
- Feature flag:
wiki_smart_redirect
Screenshots or screen recordings
Here are a screencast showing the old and new redirect logic for the wiki page:
- Before this MR, the user is redirected to the wiki home page without considering other pages.
- After this MR, The user is redirected to an existing page if the home wiki page does not exist.
| Before | After |
|---|---|
How to set up and validate locally
- Enable the feature flag in Rails console:
Feature.enable(:wiki_smart_redirect) - Create a project with wiki pages but no "home" page:
project = Project.find_by_full_path('your/project') wiki = project.wiki wiki.create_page('other-page', 'Content', format: :markdown, message: 'Create page') - Visit
http://localhost:3000/your/project/-/wikis - Verify it redirects to
/your/project/-/wikis/other-pageinstead of/wikis/home - Create a home page and verify it redirects to home:
wiki.create_page('home', 'Home content', format: :markdown, message: 'Create home') - Disable the feature flag and verify original behavior (always redirects to
/wikis/home):Feature.disable(:wiki_smart_redirect)
MR acceptance checklist
Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.
MR Checklist (@gerardo-navarro)
- Changelog entry added, if necessary
- Documentation created/updated via this MR
- Documentation reviewed by technical writer or follow-up review issue created
- Tests added for this feature/bug
- Tested in all supported browsers
- Conforms to the code review guidelines
- Conforms to the style guides
- Conforms to the javascript style guides (N/A - no JS changes)
- Conforms to the database guides (N/A - no DB changes)
- Conforms to the merge request performance guidelines
-
Feature flag added for gradual rollout (
wiki_smart_redirect) - Group wiki behavior verified (uses same shared WikiActions concern)
Edited by Gerardo Navarro