Use relative redirect for non-production environments#3894
Conversation
There was a problem hiding this comment.
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.hostnameiswww.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.
| 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 + "/"; | ||
| } |
There was a problem hiding this comment.
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.
Deploying www-ruby-lang-org with
|
| 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 |
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
f7741eb to
531d897
Compare
The root
index.htmllanguage redirect was hardcoded tohttps://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)