docusaurus icon indicating copy to clipboard operation
docusaurus copied to clipboard

Redirects not working for URLs with dots "."

Open dtszwai opened this issue 2 years ago • 2 comments

Have you read the Contributing Guidelines on issues?

Prerequisites

  • [X] I'm using the latest version of Docusaurus.
  • [ ] I have tried the npm run clear or yarn clear command.
  • [ ] I have tried rm -rf node_modules yarn.lock package-lock.json and re-installing packages.
  • [ ] I have tried creating a repro with https://new.docusaurus.io.
  • [ ] I have read the console error message carefully (if applicable).

Description

I am using the plugin-client-redirects to redirect URLs, but it appears that redirects do not work for URLs containing periods (dots). Is this intended behavior, or is there a workaround to make such redirects work properly? (use createRedirects instead?)

redirects: [
  {
    from: [
      "/test", // This works
      "/te.st", // Does not work
    ],
    to: "/another",
  },
],

Reproducible demo

No response

Steps to reproduce

  1. yarn add @docusaurus/plugin-client-redirects
  2. adds code to docusaurus.config.js

Expected behavior

When I enter 'mysite.com/te.st,' it should redirect me to 'mysite.com/another,' but it doesn't work.

Actual behavior

the expected redirection is not occurring as intended

Your environment

  • Public source code:
  • Public site URL:
  • Docusaurus version used:
  • Environment name and version (e.g. Chrome 89, Node.js 16.4):
  • Operating system and version (e.g. Ubuntu 20.04.2 LTS):

Self-service

  • [ ] I'd be willing to fix this bug myself.

dtszwai avatar Nov 03 '23 22:11 dtszwai

Hi, are you using yarn serve or some third-party server. FYI, it works if you rename build/te.st/index.html to build/te.st.html for me when using yarn serve. The reason is because our serve handler thinks .st is already an extension, so it doesn't even try to lookup for te.st/index.html. Theoretically, you should be able to make it emit te.st.html in the first place with trailingSlash: false, but our redirects plugin does not honor that.

@slorber, do you think it should output te.st.html to make this case work? There are a lot possible redirect loops to be aware of, though!

Josh-Cena avatar Nov 04 '23 06:11 Josh-Cena

Considering the redirect file te.st/index.html is emitted, it looks like an issue with the way the static deployment is served, and it's likely that different hosts lead to different behaviors.

I don't know what to do exactly but we'd rather just say that the client redirect plugin is a best effort and can't work for all use-cases. It's not really worth investing a ton of time finding the impossible common denominator that works for all cases and hosts when client redirects are antipatterns in the first place 😅

slorber avatar Nov 21 '23 18:11 slorber