Skip to content

The Cloudflare adapter strips the trailing slash, causing the redirect to become a 404 #419

Open
@Khsmty

Description

Astro Info

Astro                    v4.15.12
Node                     v22.7.0
System                   Windows (x64)
Package Manager          unknown
Output                   hybrid
Adapter                  @astrojs/cloudflare
Integrations             @astrojs/sitemap
                         @astrojs/tailwind
                         astro-icon

Describe the Bug

Below, I have it set up to redirect from /foo or /foo/ to /bar.
However, when I build this with the Cloudflare adapter, the trailing slash is removed in the _redirects file, and accessing /foo/ results in a 404.

// astro.config.mjs

export default defineConfig({
  redirects: {
    '/foo': '/bar',
    '/foo/': '/bar',
  },

  output: 'server',
  adapter: cloudflare(),
});
# dist/_redirects

/foo    /bar    301
/foo    /bar    301

What's the expected result?

The trailing slash has not been removed from the _redirects file, so it is expected that accessing /foo/ will result in a successful redirect.

# dist/_redirects

/foo    /bar    301
/foo/    /bar    301

Link to Minimal Reproducible Example

https://stackblitz.com/edit/github-fzcdgt?file=dist%2F_redirects

Participation

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

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions