facebook / docusaurus

Easy to maintain open source documentation websites.
https://docusaurus.io
MIT License
55.53k stars 8.33k forks source link

Redirects not working for URLs with dots "." #9505

Open dtszwai opened 10 months ago

dtszwai commented 10 months ago

Have you read the Contributing Guidelines on issues?

Prerequisites

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

Self-service

Josh-Cena commented 10 months ago

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!

slorber commented 9 months ago

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 😅