Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite Redirect Loop with @astrojs/[email protected] When Using trailingSlash: 'always' #499

Open
faiz9068 opened this issue Jan 9, 2025 · 0 comments

Comments

@faiz9068
Copy link

faiz9068 commented Jan 9, 2025

Astro Info

Astro                    v5.1.1
Node                     v20.14.0
System                   Windows (x64)
Package Manager          npm
Output                   server
Adapter                  @astrojs/vercel
Integrations             @astrojs/tailwind
                         astro-lottie
                         @astrojs/mdx
                         @astrojs/svelte
                         @astrojs/react
                         @astrojs/sitemap
                         sitemap-copier

Describe the Bug

When deploying to Vercel with trailingSlash: "always", routes enter an infinite redirect loop. The issue occurs even when directly accessing URLs with trailing slashes. This appears to be a regression in the Vercel adapter's handling of trailing slashes.

Reproduction

The Vercel adapter generates overlapping redirect rules in config.json:

{
  "src": "/guides",
  "headers": {
    "Location": "/guides/"
  },
  "status": 308
},
{
  "src": "/guides(?:\\/(.*?))?",
  "headers": {
    "Location": "/guides/$1/"
  },
  "status": 308
}

The second pattern matches /guides/ and attempts to redirect to /guides//, creating an infinite loop.

Steps to Reproduce

  1. Create an Astro project with configurations:
    // astro.config.mjs
    export default defineConfig({
      trailingSlash: "always",
      output: "server",
      adapter: vercel()
    });
  2. Add a route at /guides/ (either static or dynamic)
  3. add /guides/[...slug] rest route
  4. Deploy to Vercel
  5. Visit /guides/

Expected Behavior

  • /guides should redirect to /guides/ (once)
  • /guides/ should render the page without redirecting

Actual Behavior

  • Accessing /guides/ results in "Too Many Redirects" error
  • Browser shows infinite loop between /guides/ and /guides//

Configuration

// astro.config.mjs
import { defineConfig } from "astro/config";
import tailwind from "@astrojs/tailwind";
import lottie from "astro-integration-lottie";
import mdx from "@astrojs/mdx";
import vercel from "@astrojs/vercel";
import svelte from "@astrojs/svelte";
import sitemap from "@astrojs/sitemap";
import react from "@astrojs/react";

export default defineConfig({
  trailingSlash: "always",
  integrations: [
    tailwind(),
    lottie(),
    mdx(),
    svelte(),
    react(),
    sitemap({...})
  ],
  output: "server",
  adapter: vercel()
});

Related Issues

Environment

  • Platform: Vercel
  • Browser: All browsers (Chrome, Firefox, Safari)
  • Operating System: All (not OS-specific)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant