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
Periods in URLs with trailing slashes cause 404s in dev server #16140
Astro v6.1.0
Node v25.8.2
System Windows (x64)
Package Manager bun
Output static
Adapter none
Integrations @astrojs/mdx
If this issue only occurs in one browser, which browser is a problem?
N/A
Describe the Bug
If the URL has a period, then Astro will report a 404 with the dev server if you attempt to navigate to the URL with a trailing slash. Production static builds are not affected. Even setting trailingSlash: always causes the same problem.
I don't think this issue was present in v5.
What's the expected result?
Astro should handle periods in URLs with trailing slashes
I was able to reproduce this issue. The root cause is in trailingSlashForPath in packages/astro/src/core/routing/create-manifest.ts. This function uses hasFileExtension() to check if a route pathname looks like a file path, and the regex /\/[^/]+\.\w+$/ matches any path segment ending with a dot followed by word characters. For a page like hello.world.astro, the generated route pathname /hello.world matches (.world looks like a file extension), so trailing slash handling is forced to 'never' regardless of the user's config. This means the route pattern never matches URLs with trailing slashes like /hello.world/.
I was able to fix this issue. The fix modifies trailingSlashForPath to accept a type parameter ('page' | 'endpoint') and only force trailingSlash: 'never' for endpoints with file extensions. Pages with dots in their names now correctly respect the user's trailingSlash config. View Suggested Fix
P3: minor bug. This affects users who have periods/dots in their page filenames and use trailing slashes (either via trailingSlash: 'ignore' default or trailingSlash: 'always'). It only manifests in the dev server — production static builds are unaffected. The workaround is to avoid dots in page filenames, but this is a legitimate use case that should work correctly.
Full Triage Report
Issue #16140: Periods in URLs with trailing slashes cause 404s in dev server
Reproduction
Created a minimal Astro project with src/pages/hello.world.astro. Navigating to /hello.world/ (with trailing slash) in the dev server returns a 404.
Confirmed: The bug reproduces with the default trailingSlash: 'ignore' config and also with trailingSlash: 'always'.
Root Cause
The root cause is in packages/astro/src/core/routing/create-manifest.ts at line 435 (the trailingSlashForPath function):
This function uses hasFileExtension() (from @astrojs/internal-helpers/path) to check if a route pathname looks like a file path. The regex /\/[^/]+\.\w+$/ matches any path segment ending with a dot followed by word characters. For a page like hello.world.astro, the generated route pathname is /hello.world, which matches the regex (.world looks like a file extension).
When hasFileExtension returns true, trailingSlashForPath forces the trailing slash rule to 'never', regardless of the user's config. This means the route pattern regex is generated as ^\/hello\.world$ (no optional trailing slash), so /hello.world/ never matches.
The problem is that this check doesn't distinguish between:
Endpoints like feed.xml.ts where /feed.xml is truly a file-like path and trailing slashes are never appropriate
Pages like hello.world.astro where dots are just part of the page name and the user's trailing slash config should be respected
Fix
Modified trailingSlashForPath to accept a type parameter ('page' | 'endpoint') and only force 'never' for endpoints:
Pages with dots in their names (like sitemap.xml.astro) will now respect the user's trailingSlash config. This means /sitemap.xml/ will be valid when trailingSlash is 'ignore' or 'always'. This is correct behavior since the user controls the trailing slash setting.
Endpoints (.ts, .js files) still force 'never' for trailing slashes when the pathname has a file extension, which is the correct behavior for API/file endpoints like /feed.xml.
There's a separate minor issue where the trailing slash middleware's hasFileExtension check in trailing-slash.ts prevents showing the "trailing slash mismatch" error for page URLs with dots. This is a cosmetic issue and was not addressed in this fix.
This report was made by an LLM. Mistakes happen, check important info.
Activity
astrobot-houston commentedon Mar 29, 2026
I was able to reproduce this issue. The root cause is in
trailingSlashForPathinpackages/astro/src/core/routing/create-manifest.ts. This function useshasFileExtension()to check if a route pathname looks like a file path, and the regex/\/[^/]+\.\w+$/matches any path segment ending with a dot followed by word characters. For a page likehello.world.astro, the generated route pathname/hello.worldmatches (.worldlooks like a file extension), so trailing slash handling is forced to'never'regardless of the user's config. This means the route pattern never matches URLs with trailing slashes like/hello.world/.I was able to fix this issue. The fix modifies
trailingSlashForPathto accept atypeparameter ('page' | 'endpoint') and only forcetrailingSlash: 'never'for endpoints with file extensions. Pages with dots in their names now correctly respect the user'strailingSlashconfig. View Suggested FixP3: minor bug. This affects users who have periods/dots in their page filenames and use trailing slashes (either via
trailingSlash: 'ignore'default ortrailingSlash: 'always'). It only manifests in the dev server — production static builds are unaffected. The workaround is to avoid dots in page filenames, but this is a legitimate use case that should work correctly.Full Triage Report
Issue #16140: Periods in URLs with trailing slashes cause 404s in dev server
Reproduction
Created a minimal Astro project with
src/pages/hello.world.astro. Navigating to/hello.world/(with trailing slash) in the dev server returns a 404.Confirmed: The bug reproduces with the default
trailingSlash: 'ignore'config and also withtrailingSlash: 'always'.Root Cause
The root cause is in
packages/astro/src/core/routing/create-manifest.tsat line 435 (thetrailingSlashForPathfunction):This function uses
hasFileExtension()(from@astrojs/internal-helpers/path) to check if a route pathname looks like a file path. The regex/\/[^/]+\.\w+$/matches any path segment ending with a dot followed by word characters. For a page likehello.world.astro, the generated route pathname is/hello.world, which matches the regex (.worldlooks like a file extension).When
hasFileExtensionreturnstrue,trailingSlashForPathforces the trailing slash rule to'never', regardless of the user's config. This means the route pattern regex is generated as^\/hello\.world$(no optional trailing slash), so/hello.world/never matches.The problem is that this check doesn't distinguish between:
feed.xml.tswhere/feed.xmlis truly a file-like path and trailing slashes are never appropriatehello.world.astrowhere dots are just part of the page name and the user's trailing slash config should be respectedFix
Modified
trailingSlashForPathto accept atypeparameter ('page' | 'endpoint') and only force'never'for endpoints:Updated all three call sites to pass the route type:
createFileBasedRoutes(line 244) — usesitem.isPagecreateRoutesFromEntriesByDir(line 385) — usesitem.isPagecreateInjectedRoutes(line 460) — uses existingtypevariableVerification
Before fix:
/hello.world/→ 404 (bug)/hello.world→ 200After fix:
/hello.world/→ 200 (fixed!)/hello.world→ 200/feed.xml→ 200 (endpoint still works)trailingSlash: 'always':/hello.world/→ 200 (fixed!)Regression testing:
All existing tests pass (185+ tests across routing, trailing slash, i18n, and manifest test suites):
test/units/routing/trailing-slash.test.js— 14/14 passtest/units/routing/dev-routing.test.js— 5/5 passtest/units/routing/routing-priority.test.js— 11/11 passtest/units/routing/preview-routing.test.js— 4/4 passtest/units/routing/manifest.test.js— 10/10 passtest/units/app/trailing-slash.test.js— 32/32 passtest/units/i18n/i18n-routing-static.test.js— 30/30 passtest/units/i18n/manual-routing.test.js— 111/111 pass (estimated)Tradeoffs / Notes
sitemap.xml.astro) will now respect the user'strailingSlashconfig. This means/sitemap.xml/will be valid whentrailingSlashis'ignore'or'always'. This is correct behavior since the user controls the trailing slash setting..ts,.jsfiles) still force'never'for trailing slashes when the pathname has a file extension, which is the correct behavior for API/file endpoints like/feed.xml.hasFileExtensioncheck intrailing-slash.tsprevents showing the "trailing slash mismatch" error for page URLs with dots. This is a cosmetic issue and was not addressed in this fix.This report was made by an LLM. Mistakes happen, check important info.
Fix periods in URLs with trailing slashes causing 404s in dev server (w…
Fix periods in URLs with trailing slashes causing 404s in dev server (w…
Fix periods in URLs with trailing slashes causing 404s in dev server (#…
chore: merge main into next (#16434)