Dots in URL lead to 404 (regression?)
See original GitHub issue⚠️ IMPORTANT ⚠️ Please do not ignore this template. If you do, your issue will be closed immediately.
- Read the docs.
- Make sure this is a Vite issue and not a framework-specific issue. For example, if it’s a Vue SFC related bug, it should likely be reported to https://github.com/vuejs/vue-next instead.
- This is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
Describe the bug
URLs with dots are leading to a 404 error instead of correctly displaying the corresponding page.
Note that it works fine with a project created with Vue CLI but it doesn’t work with a project created with @vite/create-app (both using Vue 3 with Vue Router 4).
I guess this is a regression from https://github.com/vitejs/vite/issues/130 but many things have change with Vite 2 (especially project structure) so it’s hard for me to identify why the bug reappeared (but with some guidance I’m happy to help).
Reproduction
- 🔴 Repro created with @vite/create-app (not working): https://github.com/Deckluhm/vite-dots-url-bug
- 🟢 Repro created with Vue CLI (working): https://github.com/Deckluhm/vue-cli-dots-url-bug
Run projects and go to http://localhost:3000/just.a.test (or a similar URL).
System Info
vite
version: 2.0.1 (with @vitejs/plugin-vue 1.1.4)- Operating System: Ubuntu 20.10
- Node version: 15.10.0
- Package manager (npm/yarn/pnpm) and version: Yarn 1.22.10
Issue Analytics
- State:
- Created 3 years ago
- Reactions:32
- Comments:6 (1 by maintainers)
Top Results From Across the Web
Dots in URL causes 404 with ASP.NET mvc and IIS
URLs with the dot generate a 404. My routing is fine. If I pass in michaelphelps, without the dot, then everything works. If...
Read more >url with dot causing 404 - MSDN - Microsoft
But if url is localhost/abc.def it causes 404. following is my route details public static void RegisterRoutes(RouteCollection routes) { routes.
Read more >Enabling clean URLs cause a 404 error - Drupal Answers
I am trying to enable clean URL in a Drupal 7 website. The clean URL is supported by server, as I can see...
Read more >How To Find Broken Links Using Cypress [With Examples]
There are umpteen reasons that result in 404 errors (or broken links/dead links); the major ones are mentioned below:.
Read more >Trailing dots in url result in empty 404 page on IIS - Server Fault
The upshot of it is that there is an order-of-operations issue where the .NET handlers for various functions get mixed up and misdirect...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
There was an issue created about this already here: https://github.com/vitejs/vite/issues/2245 But it was closed because of the use of a workaround with a plugin, that may also help you while this is open. Maybe there is a limitation I’m not aware of, but this looks like a bug, and the other issue was wrongly closed.
The behaviour seems to be because vite assumes that if the final segment of the path contains
.
, the user meant to navigate to a file. This is a pretty bad assumption to take because files without.
are valid too (although, uncommon) and modern SPAs generally expect all paths except static assets to be routed toindex.html
so client-side routing can take effect.One solution could be to check existance in the file system, and if the file is not there, serve
index.html
, similar totry_files
is often configured in nginx to serve prod apps. With such an mechanism, no option like https://github.com/vitejs/vite/pull/2634 is necessary as it’ll work correctly in all cases, but it will involve one additionalstat
call on each request.