Skip to content

Conversation

@slorber
Copy link
Collaborator

@slorber slorber commented Jul 21, 2023

Motivation

Fix #6845

The client redirect plugins should allow redirecting to:

  • fully resolved URIs
  • URLs with querystring and/or hash (fully resolved / absolute / relative)

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#anchor from 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

Fully qualified URL redirects:

@slorber slorber requested review from Josh-Cena and lex111 as code owners July 21, 2023 17:27
@facebook-github-bot facebook-github-bot added the CLA Signed Signed Facebook CLA label Jul 21, 2023
@slorber slorber added the pr: bug fix This PR fixes a bug in a past release. label Jul 21, 2023
@netlify
Copy link

netlify bot commented Jul 21, 2023

[V2]

Name Link
🔨 Latest commit 1a79e0a
🔍 Latest deploy log https://app.netlify.com/sites/docusaurus-2/deploys/64bac3249be63b0008d4c588
😎 Deploy Preview https://deploy-preview-9171--docusaurus-2.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site configuration.

@github-actions
Copy link

github-actions bot commented Jul 21, 2023

⚡️ Lighthouse report for the deploy preview of this PR

URL Performance Accessibility Best Practices SEO PWA Report
/ 🟢 92 🟢 97 🟢 92 🟢 100 🟠 89 Report
/docs/installation 🟠 76 🟢 100 🟢 92 🟢 100 🟠 89 Report

@slorber slorber changed the title feat(client-redirects-plugin): support feat(client-redirects-plugin): support fully qualified urls and querystring/hash in destination/to url Jul 21, 2023
@slorber slorber added pr: new feature This PR adds a new API or behavior. and removed pr: bug fix This PR fixes a bug in a past release. labels Jul 21, 2023
@slorber slorber merged commit 09ea3bc into main Jul 21, 2023
@slorber slorber deleted the slorber/relax-redirects-to-validation branch July 21, 2023 17:54
@github-actions
Copy link

Size Change: +277 B (0%)

Total Size: 1.1 MB

Filename Size Change
website/build/assets/js/main.********.js 829 kB +277 B (0%)
ℹ️ View Unchanged
Filename Size
website/.docusaurus/globalData.json 117 kB
website/build/assets/css/styles.********.css 113 kB
website/build/index.html 41 kB

compressed-size-action

slorber added a commit to VinceCYLiao/docusaurus that referenced this pull request Aug 3, 2023
This was referenced Oct 19, 2023
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

CLA Signed Signed Facebook CLA pr: new feature This PR adds a new API or behavior.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

plugin-client-redirects should allow fully resolved URIs

3 participants