I have a project with static HTML and CSS assets stored in a subfolder under the public folder (e.g., public/admin-panel/, public/reports/). Each subfolder under the public folder contains an index.html file (e.g., public/admin-panel/index.html and public/reports/index.html).
However, if I start up my application using npm run dev (aka, vite), then it does not behave the same. If I visit http://localhost:5173/admin-panel/ then it will instead serve the index.html file contained in the root folder of my project. Only if I visit http://localhost:5173/admin-panel/index.html will it then serve up the correct index.html file.
A similar bug was patched back in October 2023 ( https://github.com/vitejs/vite/pull/14756 ) but it appears to have only been applied to index.html files contained in subfolders under the src folder. Subfolders to the public folder are still impacted.
[X] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
[X] 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 vuejs/core instead.
Describe the bug
I have a project with static HTML and CSS assets stored in a subfolder under the
public
folder (e.g.,public/admin-panel/
,public/reports/
). Each subfolder under thepublic
folder contains anindex.html
file (e.g.,public/admin-panel/index.html
andpublic/reports/index.html
).If I build my application (
npm run build
-- aka,vite build
) and serve up the preview (npm run serve
-- aka,vite preview
), then theindex.html
file is served up correctly regardless of whether I access the file via http://localhost:4173/admin-panel/ or http://localhost:4173/admin-panel/index.htmlHowever, if I start up my application using
npm run dev
(aka,vite
), then it does not behave the same. If I visit http://localhost:5173/admin-panel/ then it will instead serve theindex.html
file contained in the root folder of my project. Only if I visit http://localhost:5173/admin-panel/index.html will it then serve up the correctindex.html
file.A similar bug was patched back in October 2023 ( https://github.com/vitejs/vite/pull/14756 ) but it appears to have only been applied to
index.html
files contained in subfolders under thesrc
folder. Subfolders to thepublic
folder are still impacted.Reproduction
https://stackblitz.com/edit/vitejs-vite-sepev3?file=main.js
Steps to reproduce
Admin panel link (does not work)
and observe that it serves the rootindex.html
.Admin panel link (does work)
and observe that it correctly servespublic/admin-panel/index.html
-- displaying the "Hello world." mesage.System Info
Used Package Manager
npm
Logs
No response
Validations