You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Hosting environments that add a trailing back slash break page links #2394
Load the site in any browser by navigating directly to the url of page a: http://127.0.0.1:8080/docs/a/a
Click the link Link to page "b"
Expected behavior
Page b should load.
Actual Behavior
Page Not Found page.
Your Environment
Docusaurus version used: 2.0.0-alpha.48
Environment name and version (e.g. Chrome 78.0.3904.108, Node.js 10.17.0): Safari 13.0.5 (15608.5.11), Chrome 80.0.3987.132, Firefox 73.0.1
Operating system and version (desktop or mobile): macOS 10.15.3 (19D76)
Reproducible Demo
(Paste the link to an example repo, including a siteConfig.js, and exact instructions to reproduce the issue.)
@littlespex are you sure the browser is adding that slash? Try running your site locally and see if the slash gets added. If not, it most likely is your hosting server.
FYI I am seeing the same behavior on Netlify (adding the slash, breaking the links)
💡 If you are using Netlify, disabling Pretty URLs should solve the problem. I unchecked the first two boxes to prevent Netlify from both lowercasing the urls and.. adding the trailing slash.
I had updated the ticket description earlier to mention the hosting environment instead of the browser. Unfortunately we don’t have admin control over our docs environment and the team that runs it has enabled these url rewrite rules for other reasons. Our current workaround is to revert to docusaurus v1 which works as expected.
Hey, I found the original issue description not so easy to understand (particularly that md files are in zip files 🤪 that does not help to scan this issue). To clarify the problem, here's what I understand:
Locally you have a page at /folder/myDoc
It contains a relative link like myLink, supposed to navigate to /folder2/myTargetDoc
As this link is relative, the trailing slash added automatically breaks the link, as we now navigate to /folder/folder2/myTargetDoc and to make it work in production, we would have to write [myLink](../../folder2/myTargetDoc)
So this bug is only related to using relative links, is that correct @littlespex ?
changed the title [-]Browser added trailing back slash breaks page links[/-][+]Hosting environments that add a trailing back slash break page links[/+]on Sep 1, 2020
@slorber I believe this issue happens on any link that does not contain a trailing backslash. We had to revert to docusaurus v1, so I no longer have a working example.
But I don't know whether this would break anything else.
But it does seem to me that if you want to normalize, then allowing both /foo/bar/ and /foo/bar doesn't seem to be a very good job of normalizing to me.
I'm having the same issue, it breaks URL navigation due to HTTP proxy services. I use `Nginx in the docker, when I directly open a link without trailing slash, it redirects to HTTP domain with the port used in Nginx. Since we don't run on 443 port it breaks the public link.
For example, if I try to open https://domain.com/a it redirects to http://domain.com:8080/a/ and it fails to load the page. But if you open https://domain.com/a/ it works fine. Does anyone have the same issue?
Reacted by Joseph Stiles, Stefan Dirix, Andi Exer, wallbaa and Srinivas Reddy
Activity
bravo-kernel commentedon Mar 14, 2020
@littlespex are you sure the browser is adding that slash? Try running your site locally and see if the slash gets added. If not, it most likely is your hosting server.
FYI I am seeing the same behavior on Netlify (adding the slash, breaking the links)
bravo-kernel commentedon Mar 14, 2020
💡 If you are using Netlify, disabling
Pretty URLsshould solve the problem. I unchecked the first two boxes to prevent Netlify from both lowercasing the urls and.. adding the trailing slash.littlespex commentedon Mar 14, 2020
I had updated the ticket description earlier to mention the hosting environment instead of the browser. Unfortunately we don’t have admin control over our docs environment and the team that runs it has enabled these url rewrite rules for other reasons. Our current workaround is to revert to docusaurus v1 which works as expected.
davidhagg commentedon Apr 30, 2020
We are having this issue too running on an Azure Webservice.
dotansimha commentedon May 19, 2020
Same here, with GH Pages.
dotansimha commentedon May 19, 2020
My current way to workaround that:
static/js/fix-location.jswith:docusaurus.config.js:Workaround trailing slashes on website
Workaround trailing slashes on website
Workaround trailing slashes on website (#3531)
cliedeman commentedon Jun 15, 2020
@dotansimha Thanks for the workaround.
Anyone else who uses this fix don't forget to include your
baseUrlif your site is not hosted at the rootslorber commentedon Aug 31, 2020
Hey, I found the original issue description not so easy to understand (particularly that md files are in zip files 🤪 that does not help to scan this issue). To clarify the problem, here's what I understand:
/folder/myDoc/folder2/myTargetDoc/folder/folder2/myTargetDocand to make it work in production, we would have to write[myLink](../../folder2/myTargetDoc)So this bug is only related to using relative links, is that correct @littlespex ?
Is it the problem you also encounter @davidhagg @dotansimha @cliedeman ? Or is it something else?
We should find a solution to this problem (track #3372), but in the meantime, possible workarounds are:
[myLink](/folder2/myTargetDoc)[myLink](../folder2/myTargetDoc.md)[-]Browser added trailing back slash breaks page links[/-][+]Hosting environments that add a trailing back slash break page links[/+]littlespex commentedon Sep 1, 2020
@slorber I believe this issue happens on any link that does not contain a trailing backslash. We had to revert to docusaurus v1, so I no longer have a working example.
Workaround trailing slashes on website (#3531)
MarkFarmiloe commentedon Apr 8, 2021
In docusaurus/packages/docusaurus/src/client/normalizeLocation.ts
any trailing /index.html is knocked off the path.
If you knock off any trailing / as well with
pathname = pathname.replace(/\/$/, '');on line 23, this seems to fix this bug.
But I don't know whether this would break anything else.
But it does seem to me that if you want to normalize, then allowing both /foo/bar/ and /foo/bar doesn't seem to be a very good job of normalizing to me.
Fix meta#2394
veeramarni commentedon Apr 27, 2021
I'm having the same issue, it breaks URL navigation due to HTTP proxy services. I use `Nginx in the docker, when I directly open a link without trailing slash, it redirects to HTTP domain with the port used in Nginx. Since we don't run on 443 port it breaks the public link.
For example, if I try to open
https://domain.com/ait redirects tohttp://domain.com:8080/a/and it fails to load the page. But if you openhttps://domain.com/a/it works fine. Does anyone have the same issue?slorber commentedon Apr 28, 2021
FYI there is a related issue here: #3372 so I'm going to close this one.
I proposed a temporary workaround here: #3372 (comment)
Using client-side normalization is not bad but it won't prevent the host to eventually add a useless server redirect to the URL with a trailing slash.
I used it successfully on React-Native website:
The PR I linked to contains a plugin that to will prevent the host to add a trailing slash and prevent a useless server redirect.
Please try my workaround with your specific hosting env, and report on the other issue if the workaround works or not for your usecase.
If the workaround works for everyone, I'll generalize it and add it by default in Docusaurus core, so your feedback is important.