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:

  1. Users are always redirected to /wikis/home
  2. If "home" doesn't exist but other pages do, users get a 404 error
  3. 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-page200 shows page

Technical changes

  • Added Wiki#first_page and Wiki#first_page_slug methods to determine the appropriate target page
  • Changed route from hardcoded redirect to controller index action
  • Added WikiActions#index with feature flag check
  • Excluded index action from load_sidebar before_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.

🛠️ with ❤️ at Siemens

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-page instead 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)
Edited by Gerardo Navarro

Merge request reports

Loading