vercel / vercel/next.js

Issue with handling multiple trailing slashes and intermediate redirects

Open
#81,068 1 comment 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dynamic Routes
Dominant language
JavaScript
Stars
142k
Forks
32.4k
Avg merge
2d 14h
Merged PRs (30d)
351

Description

Link to the code that reproduces this issue

https://codesandbox.io/p/sandbox/github/vercel/next.js/tree/canary/examples/reproduction-template-pages

To Reproduce

Description:

When a URL with multiple trailing slashes (e.g. ////) is accessed in Next.js, it first redirects to a URL with a single trailing slash (e.g. /) and only then redirects again to the final URL without the trailing slash. This causes unnecessary intermediate redirects.

Steps to reproduce:
1. Go to a URL like https://example.com////
2. The browser first redirects to https://example.com/
3. Then, it redirects again to https://example.com (final destination without trailing slash)

Expected behavior:

Next.js should automatically handle URLs with multiple trailing slashes and redirect directly to the destination URL without any intermediate redirect.

Current behavior:

The server first redirects from //// to /, and then to the final URL without the trailing slash. This results in unnecessary redirects.

Possible solution:

Next.js should implement a feature that detects multiple trailing slashes and redirects directly to the proper URL without any intermediate redirect.

Additional information:

This behavior may cause slower page loads due to multiple HTTP requests. It would be beneficial to add a feature to handle multiple slashes in a single redirect instead of chaining redirects.

Current vs. Expected behavior

Current behavior:

When a URL with multiple trailing slashes (e.g. ////) is accessed, the server first redirects to a URL with a single trailing slash (e.g. /). After that, a second redirect occurs to the final destination URL without the trailing slash (e.g. https://example.com). This results in two unnecessary redirects (301) instead of one.

Example:
• URL: https://example.com////
• Step 1: Redirect to https://example.com/ (single slash).
• Step 2: Redirect to https://example.com (final URL without trailing slash).

Expected behavior:

When a URL with multiple trailing slashes (e.g. ////) is accessed, Next.js should directly redirect to the final destination URL without any intermediate redirect (e.g. https://example.com). There should be no extra redirects or steps involved.

Example:
• URL: https://example.com////
• Expected behavior: Directly redirect to https://example.com.

Provide environment information
Next.js: v15.4.0-canary.102 (June 2025)
Node.js: v20.9.0 (October 2023)
npm: v11.4.2 (June 2025)
Which area(s) are affected? (Select all that apply)

Dynamic Routes

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the linked CodeSandbox reproduction and trace Next.js's trailing-slash redirect handling for URLs ending in multiple slashes. Confirm the current two-step redirect, then verify that the final URL is reached in one redirect without regressing normal trailing-slash behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, next.js, node.js
Domain
web-dev
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.