Skip to content

Fix PR preview 404s - Deploy via gh-pages branch#15

Merged
D4koon merged 7 commits intomainfrom
copilot/fix-pr-preview-404-error
Jan 8, 2026
Merged

Fix PR preview 404s - Deploy via gh-pages branch#15
D4koon merged 7 commits intomainfrom
copilot/fix-pr-preview-404-error

Conversation

Copy link
Contributor

Copilot AI commented Jan 8, 2026

The repository was using GitHub's native Pages deployment via static.yml workflow, while the pr-preview.yml workflow was deploying PR previews to the gh-pages branch. These two deployment methods conflicted, causing 404s at URLs like https://d4koon.github.io/Holiday-Planner/pr-13/.

After updating GitHub Pages settings to serve from the gh-pages branch, all workflows have been updated to use the gh-pages branch deployment method.

Issue Identified

The main site was deployed using static.yml with GitHub Actions native deployment (actions/deploy-pages@v4), while PR previews were attempting to deploy to the gh-pages branch. These two deployment methods conflict - GitHub Pages can only serve from one source at a time.

Changes Made

  • Added deploy-main.yml workflow - Deploys main branch to gh-pages root on push to main, preserving PR preview directories via keep_files: true

  • Fixed redirect URLs - Changed url=../../ to url=../ in closed PR redirect pages in pr-preview.yml

    • Old: Redirected to https://d4koon.github.io/ (user's root GitHub Pages)
    • New: Redirects to https://d4koon.github.io/Holiday-Planner/ (project site)
  • Removed fix-pr-12-preview.yml workflow - Consolidated to single PR preview workflow (pr-preview.yml)

  • PR preview workflow - Already configured to deploy to gh-pages branch subdirectories (pr-<number>/)

Deployment Architecture

Both workflows now use peaceiris/actions-gh-pages@v3 to deploy to the gh-pages branch:

  • Main site: Deployed to gh-pages root (/) on push to main branch
  • PR previews: Deployed to gh-pages subdirectories (/pr-/) when PRs are opened/updated
  • Cleanup: PR preview replaced with redirect page when PR is closed

Next Steps

After merging this PR:

  1. The static.yml workflow on main should be removed (no longer needed)
  2. Manually trigger "Deploy Main Site to GitHub Pages" workflow once from Actions tab to deploy the main site
  3. PR previews will automatically work for future PRs
Original prompt

The pull-requests previews as wepages does still not work for example for pr #13 it displayed this content:
404
File not found

The site configured at this address does not contain the requested file.

If this is your site, make sure that the filename case matches the URL as well as any file permissions.
For root URLs (like http://example.com/) you must provide an index.html file.

Read the full documentation for more information about using GitHub Pages.
on this webpage:
https://d4koon.github.io/Holiday-Planner/pr-13/


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits January 8, 2026 00:23
Co-authored-by: D4koon <13141819+D4koon@users.noreply.github.com>
Co-authored-by: D4koon <13141819+D4koon@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix 404 error on pull request previews Fix PR preview 404s by deploying main site to gh-pages root Jan 8, 2026
Copilot AI requested a review from D4koon January 8, 2026 00:26
@D4koon
Copy link
Owner

D4koon commented Jan 8, 2026

@copilot https://d4koon.github.io/Holiday-Planner/ does work for me and does show the state of the main branch
could it be configuration issue with the github pages, that need to be changed so that other urls are accessable?

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot https://d4koon.github.io/Holiday-Planner/ does work for me and does show the state of the main branch
could it be configuration issue with the github pages, that need to be changed so that ot...

Great! The main site at https://d4koon.github.io/Holiday-Planner/ is working correctly.

For GitHub Pages configuration, the repository should be set to deploy from the gh-pages branch with the root directory (/). This configuration allows both the main site and PR preview subdirectories (like /pr-15/) to be accessible.

If PR preview URLs aren't accessible, it might be because:

  1. The PR preview workflow hasn't deployed them yet (it only runs when PRs are opened/updated)
  2. There's a GitHub Pages setting that needs adjustment

Can you confirm whether PR preview URLs like https://d4koon.github.io/Holiday-Planner/pr-15/ are accessible or if you're getting 404s on those URLs?

@D4koon
Copy link
Owner

D4koon commented Jan 8, 2026

@copilot I changed a setting now can you cleanup all preview workflows i only want one
And how can i try if it works?

Co-authored-by: D4koon <13141819+D4koon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot I changed a setting now can you cleanup all preview workflows i only want one
And how can i try if it works?

Done! Removed fix-pr-12-preview.yml in commit 1a4bb34. You now have one PR preview workflow (pr-preview.yml).

To test if PR previews work:

  1. Test deployment: Open a new PR (or push to this PR after merging)

    • The workflow will automatically deploy and comment with the preview URL
    • Visit https://d4koon.github.io/Holiday-Planner/pr-<number>/ to see your changes
  2. Test cleanup: Close/merge a PR

    • The workflow will replace the preview with a redirect page
    • Visiting the old preview URL should redirect to the main site after 5 seconds

The main site (https://d4koon.github.io/Holiday-Planner/) should continue working normally.

@D4koon
Copy link
Owner

D4koon commented Jan 8, 2026

@copilot Im not sure whats going on but you are assuming the page https://d4koon.github.io/Holiday-Planner/ is serverd from the branch gh-pages, which is not the case, im not sure from where it is served...
Maybe you can look at the .github/workflows/static.yml i think this is the workflow that creates the page

Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot Im not sure whats going on but you are assuming the page https://d4koon.github.io/Holiday-Planner/ is serverd from the branch gh-pages, which is not the case, im not sure from where it is ser...

You're absolutely right! I misunderstood the setup. The static.yml workflow uses GitHub's native Pages deployment (not gh-pages branch), which is why my deploy-main-site.yml approach won't work.

The issue is that pr-preview.yml deploys to the gh-pages branch, but GitHub Pages is configured to deploy from the static.yml workflow instead. This means PR preview directories on gh-pages are never served.

Two options to fix this:

  1. Keep static.yml for main site + Remove PR preview feature (simplest)
  2. Switch to gh-pages branch method for both main site and PR previews (requires changing Pages settings to deploy from gh-pages branch instead of GitHub Actions)

Which approach would you prefer? If you want PR previews to work, option 2 is needed.

…flow

Co-authored-by: D4koon <13141819+D4koon@users.noreply.github.com>
Copilot AI changed the title Fix PR preview 404s by deploying main site to gh-pages root Identify and fix PR preview 404 issue - deployment method conflict Jan 8, 2026
@D4koon
Copy link
Owner

D4koon commented Jan 8, 2026

@copilot i changed the page-settings now to serve the gh-pages branch, update all workflows accordingly

Co-authored-by: D4koon <13141819+D4koon@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jan 8, 2026

@copilot i changed the page-settings now to serve the gh-pages branch, update all workflows accordingly

Done! Added deploy-main.yml workflow in commit 7d047eb to deploy the main branch to gh-pages root.

Workflows configured for gh-pages deployment:

  • deploy-main.yml - Deploys main branch to gh-pages root (preserves PR preview directories)
  • pr-preview.yml - Already configured to deploy PR previews to gh-pages subdirectories

After merging:

  1. Delete static.yml from main branch (no longer needed)
  2. Manually trigger "Deploy Main Site to GitHub Pages" workflow once
  3. PR previews will work automatically for all future PRs

Co-authored-by: D4koon <13141819+D4koon@users.noreply.github.com>
Copilot AI changed the title Identify and fix PR preview 404 issue - deployment method conflict Fix PR preview 404s - Deploy via gh-pages branch Jan 8, 2026
@D4koon D4koon marked this pull request as ready for review January 8, 2026 01:11
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

🎉 Preview Deployed!

Your PR preview is ready for review:

🔗 Preview URL: https://D4koon.github.io/Holiday-Planner/pr-15/

The preview will automatically update with new commits.

@D4koon D4koon merged commit 4cb2645 into main Jan 8, 2026
2 checks passed
@github-actions
Copy link
Contributor

github-actions bot commented Jan 8, 2026

🧹 Preview Cleaned Up

The preview for this PR has been removed since the PR was closed.

github-actions bot added a commit that referenced this pull request Jan 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants