withastro / adapters

Home for Astro's core maintained adapters
70 stars 41 forks source link

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

Open Khsmty opened 1 month ago

Khsmty commented 1 month ago

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