Skip to content

Periods in URLs with trailing slashes cause 404s in dev server #16140

Closed

Description

@ericswpark

Astro Info

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

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-mkbc4rxj?file=src%2Fpages%2Findex.astro

Participation

  • I am willing to submit a pull request for this issue.

Activity

  1. astrobot-houston commented on Mar 29, 2026

    @astrobot-houston
    Contributor

    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):

    const trailingSlashForPath = (
      pathname: string | null,
      config: AstroConfig,
    ): AstroConfig['trailingSlash'] =>
      pathname && hasFileExtension(pathname) ? 'never' : config.trailingSlash;

    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:

    const trailingSlashForPath = (
      pathname: string | null,
      config: AstroConfig,
      type: 'page' | 'endpoint',
    ): AstroConfig['trailingSlash'] =>
      type === 'endpoint' && pathname && hasFileExtension(pathname) ? 'never' : config.trailingSlash;

    Updated all three call sites to pass the route type:

    1. createFileBasedRoutes (line 244) — uses item.isPage
    2. createRoutesFromEntriesByDir (line 385) — uses item.isPage
    3. createInjectedRoutes (line 460) — uses existing type variable

    Verification

    Before fix:

    • /hello.world/ → 404 (bug)
    • /hello.world → 200

    After fix:

    • /hello.world/ → 200 (fixed!)
    • /hello.world → 200
    • /feed.xml → 200 (endpoint still works)
    • With 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 pass
    • test/units/routing/dev-routing.test.js — 5/5 pass
    • test/units/routing/routing-priority.test.js — 11/11 pass
    • test/units/routing/preview-routing.test.js — 4/4 pass
    • test/units/routing/manifest.test.js — 10/10 pass
    • test/units/app/trailing-slash.test.js — 32/32 pass
    • test/units/i18n/i18n-routing-static.test.js — 30/30 pass
    • test/units/i18n/manual-routing.test.js — 111/111 pass (estimated)

    Tradeoffs / Notes

    • 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.

  2. added
    - P3: minor bug
    pkg: astro
    and removed
    triage: needs triage
    on Mar 29, 2026
  3. added a commit that references this issue on Apr 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    - P3: minor bugpkg: astro

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions