Skip to content

Conversation

@Aman-Cool
Copy link

Fix: Double-Slash Redirect Paths on GitHub Pages Deployments

Summary

This PR fixes a critical redirect bug in gatsby-node.js that generates malformed double-slash (//) paths during GitHub Pages (CI=true) builds. These malformed redirects break trailing-slash navigation across the site and negatively impact SEO.

The issue affects all dynamically created pages and only manifests in production GitHub Pages deployments, making it difficult to detect during local development.


Problem Description

When CI=true, Gatsby creates redirects intended to normalize trailing-slash URLs. However, the current logic incorrectly prepends / to paths that already start with /, producing invalid redirect paths.

Example

Given a valid slug:

/blog/meshery/my-post

The current redirect logic generates:

fromPath: //blog/meshery/my-post/
toPath:   //blog/meshery/my-post

This results in broken redirects for URLs with trailing slashes.


Affected Areas

  • File: gatsby-node.js

  • Lines:

    • 42–46 (onCreatePage)
    • 65–70 (envCreatePage)
  • Deployment Target: GitHub Pages (CI=true)

  • Pages Impacted:

    • Blog posts
    • News articles
    • Events
    • Programs
    • Careers
    • Member profiles
    • Integrations
    • Workshops
    • Labs
    • Handbook pages
    • Learning content
      (1000+ pages total)

Root Cause

  • All slugs generated in onCreateNode are explicitly prefixed with /:

    slug = `/${collection}/${slugify(node.frontmatter.title)}`;
  • Redirect creation logic incorrectly assumes path and matchPath do not start with /.

  • This mismatch causes double-slash paths (//) in redirect rules.


Reproduction Steps

Production Preview

  1. Open any PR in the layer5 repository

  2. Wait for the GitHub Pages preview build

  3. Open any dynamic page (blog, event, etc.)

  4. Manually add a trailing slash to the URL
    Example:

    /blog/meshery/my-post/
  5. Observe broken or incorrect redirect behavior

Local

CI=true npm run build

Inspect generated redirect HTML files in public/ and note double-slash paths in meta refresh tags.


Fix Implemented

Removed the extra leading / when constructing redirect paths.

envCreatePage (lines 65–70)

createRedirect({
  fromPath: `${path}/`,
  toPath: path,
  redirectInBrowser: true,
  isPermanent: true,
});

onCreatePage (lines 42–46)

createRedirect({
  fromPath: `${page.matchPath}/`,
  toPath: page.matchPath,
  redirectInBrowser: true,
  isPermanent: true,
});

Impact After Fix

  • ✅ Trailing-slash URLs redirect correctly
  • ✅ Canonical URLs restored for SEO
  • ✅ No more silent redirect failures
  • ✅ GitHub Pages deployment behaves correctly
  • ✅ Shared links and documentation URLs remain reliable

Why This Matters

This fix prevents widespread broken navigation and SEO degradation across the site’s primary production deployment. It ensures consistent, predictable URL behavior for users, contributors, and search engines alike.


Checklist

  • Fix double-slash redirect paths
  • Preserve existing URL structure
  • No breaking changes to local development
  • Verified behavior in CI=true builds

Please review and merge to restore correct redirect behavior on GitHub Pages.

@Aman-Cool
Copy link
Author

Hi @kishore08-07 @leecalcote @Rajesh-Nagarajan-11,
This PR fixes a GitHub Pages–specific redirect issue where trailing-slash redirects were being generated with malformed double-slash (//) paths. The problem was caused by redirect logic prepending / to paths that already include a leading slash, affecting all dynamically generated pages in CI=true builds.
The fix removes the redundant leading slash so canonical redirects work correctly, restoring trailing-slash navigation and preventing SEO issues on the GitHub Pages deployment.
Would appreciate a review when you get a chance. Thanks!

@l5io
Copy link
Contributor

l5io commented Jan 18, 2026

🚀 Preview for commit e7c7254 at: https://696cb148b4314a50f9671f57--layer5.netlify.app

@CodexRaunak CodexRaunak added the issue/dco Commit sign-off instructions label Jan 18, 2026
@github-actions
Copy link

🚨 Alert! Git Police! We couldn’t help but notice that one or more of your commits is missing a sign-off. A what? A commit sign-off (your email address).

To amend the commits in this PR with your signoff using the instructions provided in the DCO check.

To configure your dev environment to automatically signoff on your commits in the future, see these instructions.


        Be sure to join the community, if you haven't yet and please leave a ⭐ star on the project 😄

1 similar comment
@github-actions
Copy link

🚨 Alert! Git Police! We couldn’t help but notice that one or more of your commits is missing a sign-off. A what? A commit sign-off (your email address).

To amend the commits in this PR with your signoff using the instructions provided in the DCO check.

To configure your dev environment to automatically signoff on your commits in the future, see these instructions.


        Be sure to join the community, if you haven't yet and please leave a ⭐ star on the project 😄

@CodexRaunak
Copy link
Contributor

@Aman-Cool Thank you for your contribution! Let's discuss this during the website call tomorrow at 6:30 PM IST | 7 AM CST Add it as an agenda item to the meeting minutes, if you would 🙂

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area/site-config issue/dco Commit sign-off instructions

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants