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 🙂

@saurabhraghuvanshii
Copy link
Member

@Aman-Cool sign your commit

@l5io
Copy link
Contributor

l5io commented Jan 19, 2026

🚀 Preview for commit c0159c5 at: https://696e6baa451a44565ba62ac1--layer5.netlify.app

@saurabhraghuvanshii
Copy link
Member

@Aman-Cool attach video before and after

@rishiraj38
Copy link
Contributor

@Aman-Cool Please Read the DCO And Make a signed commit .

@Aman-Cool Aman-Cool force-pushed the fix/double-slash-redirects branch 2 times, most recently from 6ece969 to 6634f86 Compare January 19, 2026 19:56
@l5io
Copy link
Contributor

l5io commented Jan 19, 2026

🚀 Preview for commit 6634f86 at: https://696e8fb51ff71c63a670dcef--layer5.netlify.app

@l5io
Copy link
Contributor

l5io commented Jan 21, 2026

🚀 Preview for commit 7a62af1 at: https://69703d4df4e56989fce8f8f8--layer5.netlify.app

@leecalcote
Copy link
Member

@Aman-Cool, thanks. If this is a "critical" problem, please create an issue documenting it. Where do you see this issue manifesting? Capture network request redirects, and include in the issue, if that is what is happening. Or please point to a hyperlink on the site that includes //, if that is what is happening.

How long has the site been publishing with an extra forward slash? Please point to the offending commit.

@leecalcote
Copy link
Member

@Aman-Cool, cut in-half the amount of AI posted content, so that the bug, how it is manifesting, and the proposed fix are concisely conveyed.

Copy link
Member

@leecalcote leecalcote left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sync your fork/branch. Only include your commits in this PR, not those from others.

Signed-off-by: Aman-Cool <aman017102007@gmail.com>
@Aman-Cool Aman-Cool force-pushed the fix/double-slash-redirects branch from 7a62af1 to e87da33 Compare January 21, 2026 05:10
@l5io
Copy link
Contributor

l5io commented Jan 21, 2026

🚀 Preview for commit e87da33 at: https://697062fb771ca3df49159b8f--layer5.netlify.app

@Aman-Cool
Copy link
Author

@leecalcote thanks. This occurs only in GitHub Pages builds (CI=true) and is generated at build time by Gatsby redirects, not from authored links. The // paths appear in trailing-slash redirect artifacts and network redirects, which is why this isn’t visible locally.
I’ll open an issue with repro steps, redirect output, and the originating commit, and link it here.

@Aman-Cool
Copy link
Author

Sync your fork/branch. Only include your commits in this PR, not those from others.

Done — synced my fork and cleaned up the branch. This PR now contains only my commits.

@Aman-Cool Aman-Cool requested a review from leecalcote January 21, 2026 06:21
@Bhumikagarggg
Copy link

Bhumikagarggg commented Jan 26, 2026

@Aman-Cool Thank you for your contribution! Let's discuss this during the website call today 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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants