Skip to content

Use relative redirect for non-production environments#3894

Merged
hsbt merged 1 commit intomasterfrom
fix-preview-redirect
Apr 7, 2026
Merged

Use relative redirect for non-production environments#3894
hsbt merged 1 commit intomasterfrom
fix-preview-redirect

Conversation

@hsbt
Copy link
Copy Markdown
Member

@hsbt hsbt commented Apr 7, 2026

The root index.html language redirect was hardcoded to https://www.ruby-lang.org/, which caused Cloudflare Pages preview deployments (e.g. *.pages.dev) to redirect away from the preview site to the production site. This made it impossible to verify changes through preview URLs.

Instead of listing known local hostnames, redirect to the absolute production URL only when the hostname is www.ruby-lang.org, and use a relative path otherwise. This keeps production behavior unchanged while making preview deployments and any other non-production environments work correctly.

ref: #3888 (comment)

Copilot AI review requested due to automatic review settings April 7, 2026 04:51
@hsbt hsbt requested a review from a team as a code owner April 7, 2026 04:51
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Updates the root language-redirect logic in index.html so non-production environments (e.g., Cloudflare Pages preview deployments) don’t redirect users away to the production domain, while keeping production behavior unchanged.

Changes:

  • Redirects to the absolute production URL only when window.location.hostname is www.ruby-lang.org.
  • Uses a relative redirect (/<lang>/) for all other hostnames (previews, staging, local, etc.).

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 27 to 32
var host = window.location.hostname;
var isLocal = (host === 'localhost' || host === '127.0.0.1' || host === '::1');
if (isLocal) {
document.location = "/" + language + "/";
} else {
if (host === 'www.ruby-lang.org') {
document.location = "https://www.ruby-lang.org/" + language + "/";
} else {
document.location = "/" + language + "/";
}
Copy link

Copilot AI Apr 7, 2026

Choose a reason for hiding this comment

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

The new host-based redirect keeps JS-enabled previews on their own host, but the <noscript> fallback (meta refresh + link) below still points at https://www.ruby-lang.org/en/, which will continue to bounce non-JS clients (and any tooling that doesn’t execute JS) away from preview deployments. Consider switching the noscript URL(s) to a relative path (e.g. /en/) so production behavior remains correct while previews also work without JS.

Copilot uses AI. Check for mistakes.
@cloudflare-workers-and-pages
Copy link
Copy Markdown

cloudflare-workers-and-pages bot commented Apr 7, 2026

Deploying www-ruby-lang-org with  Cloudflare Pages  Cloudflare Pages

Latest commit: 531d897
Status: ✅  Deploy successful!
Preview URL: https://a0e1ae13.www-ruby-lang-org.pages.dev
Branch Preview URL: https://fix-preview-redirect.www-ruby-lang-org.pages.dev

View logs

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@hsbt hsbt force-pushed the fix-preview-redirect branch from f7741eb to 531d897 Compare April 7, 2026 05:03
@hsbt hsbt merged commit 2de567e into master Apr 7, 2026
3 checks passed
@hsbt hsbt deleted the fix-preview-redirect branch April 7, 2026 05:06
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