-
-
Notifications
You must be signed in to change notification settings - Fork 9.6k
feat(client-redirects-plugin): support fully qualified urls and querystring/hash in destination/to url #9171
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
✅ [V2]
To edit notification comments on pull requests, go to your Netlify site configuration. |
⚡️ Lighthouse report for the deploy preview of this PR
|
|
Size Change: +277 B (0%) Total Size: 1.1 MB
ℹ️ View Unchanged
|
slorber
added a commit
to VinceCYLiao/docusaurus
that referenced
this pull request
Aug 3, 2023
…string/hash in destination/to url (facebook#9171)
This was referenced Oct 19, 2023
2 tasks
7 tasks
ptgott
added a commit
to gravitational/docs-website
that referenced
this pull request
May 15, 2025
In order to migrate the legacy custom site to Docusaurus, we added logic to the Docusaurus config to convert redirects to use the Docusaurus format. The logic included some steps to rewrite redirect sources and desinations. This change adjusts the logic to validate redirects instead and throw errors on malformed redirects. This way, it is easier to troubleshoot issues with redirects, since the redirects that a documentation author would see are the same ones that Docusaurus processes. As part of this, this change adds a rule to require a leading slash in redirect paths. When validating redirects, Docusaurus ignores destinations that do not begin with a slash, causing unexpected issues for custom logic in the docs engine that expects redirect paths to begin with slashes. For context, see the following file in facebook/docusaurus#9171: packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts
ptgott
added a commit
to gravitational/docs-website
that referenced
this pull request
May 22, 2025
In order to migrate the legacy custom site to Docusaurus, we added logic to the Docusaurus config to convert redirects to use the Docusaurus format. The logic included some steps to rewrite redirect sources and desinations. This change adjusts the logic to validate redirects instead and throw errors on malformed redirects. This way, it is easier to troubleshoot issues with redirects, since the redirects that a documentation author would see are the same ones that Docusaurus processes. As part of this, this change adds a rule to require a leading slash in redirect paths. When validating redirects, Docusaurus ignores destinations that do not begin with a slash, causing unexpected issues for custom logic in the docs engine that expects redirect paths to begin with slashes. For context, see the following file in facebook/docusaurus#9171: packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts
github-merge-queue bot
pushed a commit
to gravitational/docs-website
that referenced
this pull request
May 22, 2025
In order to migrate the legacy custom site to Docusaurus, we added logic to the Docusaurus config to convert redirects to use the Docusaurus format. The logic included some steps to rewrite redirect sources and desinations. This change adjusts the logic to validate redirects instead and throw errors on malformed redirects. This way, it is easier to troubleshoot issues with redirects, since the redirects that a documentation author would see are the same ones that Docusaurus processes. As part of this, this change adds a rule to require a leading slash in redirect paths. When validating redirects, Docusaurus ignores destinations that do not begin with a slash, causing unexpected issues for custom logic in the docs engine that expects redirect paths to begin with slashes. For context, see the following file in facebook/docusaurus#9171: packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts
github-merge-queue bot
pushed a commit
to gravitational/docs-website
that referenced
this pull request
May 22, 2025
In order to migrate the legacy custom site to Docusaurus, we added logic to the Docusaurus config to convert redirects to use the Docusaurus format. The logic included some steps to rewrite redirect sources and desinations. This change adjusts the logic to validate redirects instead and throw errors on malformed redirects. This way, it is easier to troubleshoot issues with redirects, since the redirects that a documentation author would see are the same ones that Docusaurus processes. As part of this, this change adds a rule to require a leading slash in redirect paths. When validating redirects, Docusaurus ignores destinations that do not begin with a slash, causing unexpected issues for custom logic in the docs engine that expects redirect paths to begin with slashes. For context, see the following file in facebook/docusaurus#9171: packages/docusaurus-plugin-client-redirects/src/collectRedirects.ts
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Fix #6845
The client redirect plugins should allow redirecting to:
The validation has been related to any string, because if we support full/absolute/relative almost all strings are valid candidates, and creating a robust validator for that is quite hard.
Historically the redirects forwarded the
?search#anchorfrom the redirect source. Now if the destination/target URL has a qs/hash, we don't do this forwarding anymore and consider the destination URL provided by the user is in its final form. We could improve that logic later if needed but that seems good enough for now.Note: I'm not 100% sure this is perfectly retro-compatible, some difficult-to-detect subtle behavior could have changed a bit, so we won't backport this PR and keep it for Docusaurus v3.
Test Plan
Unit tests + dogfood
Test links
Local redirects
https://deploy-preview-9171--docusaurus-2.netlify.app/home/ => to local home
https://deploy-preview-9171--docusaurus-2.netlify.app/home/?q=1#hash => to local home with q/h forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/qs => to local home with qs
https://deploy-preview-9171--docusaurus-2.netlify.app/home/qs?q=1#hash => to local home with qs and no forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/anchor => to local home with anchor
https://deploy-preview-9171--docusaurus-2.netlify.app/home/anchor?q=1#hash => to local home with anchor and no forwarding
Fully qualified URL redirects:
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute => to prod home
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute?q=1#hash => to prod home with q/h forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/qs => to prod home with qs
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/qs?q=1#hash => to prod home with qs and no forwarding
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/anchor => to prod home with anchor
https://deploy-preview-9171--docusaurus-2.netlify.app/home/absolute/anchor?q=1#hash => to prod home with anchor and no forwarding