diff --git a/.changeset/tiny-dodos-melt.md b/.changeset/tiny-dodos-melt.md new file mode 100644 index 0000000000..66d4717b6b --- /dev/null +++ b/.changeset/tiny-dodos-melt.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Fix loading of non-index routes that end with `index.html` diff --git a/packages/astro/src/vite-plugin-astro-server/route.ts b/packages/astro/src/vite-plugin-astro-server/route.ts index 85bf969f9d..cc8439fa56 100644 --- a/packages/astro/src/vite-plugin-astro-server/route.ts +++ b/packages/astro/src/vite-plugin-astro-server/route.ts @@ -81,7 +81,10 @@ export async function matchRoute( // Try without `.html` extensions or `index.html` in request URLs to mimic // routing behavior in production builds. This supports both file and directory // build formats, and is necessary based on how the manifest tracks build targets. - const altPathname = pathname.replace(/(?:index)?\.html$/, ''); + const altPathname = pathname + .replace(/\/index\.html$/, '/') + .replace(/\.html$/, ''); + if (altPathname !== pathname) { return await matchRoute(altPathname, manifestData, pipeline); } diff --git a/packages/astro/test/dev-routing.test.js b/packages/astro/test/dev-routing.test.js index cc0a3fa1c0..c6a19fc4e4 100644 --- a/packages/astro/test/dev-routing.test.js +++ b/packages/astro/test/dev-routing.test.js @@ -321,6 +321,11 @@ describe('Development Routing', () => { assert.equal(response.status, 200); }); + it('200 when loading /base-index.html', async () => { + const response = await fixture.fetch('/base-index.html'); + assert.equal(response.status, 200); + }); + it('200 when loading /', async () => { const response = await fixture.fetch('/'); assert.equal(response.status, 200); diff --git a/packages/astro/test/fixtures/without-site-config/src/pages/base-index.astro b/packages/astro/test/fixtures/without-site-config/src/pages/base-index.astro new file mode 100644 index 0000000000..76e198f3da --- /dev/null +++ b/packages/astro/test/fixtures/without-site-config/src/pages/base-index.astro @@ -0,0 +1 @@ +