question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Trailing slashes on root pages return 404

See original GitHub issue

Is your feature request related to a problem? Please describe. Accessing root pages with a trailing slash (often how links get formatted in applications and sites we push them out to) returns the 404 page.

Describe the solution you’d like I can see that Next@9.4.5, which is currently in canary, solves or at least addresses this problem, so hopefully this is something that can be maintained here as well, if the next update brings with it some additional resources to manage by this component.

Describe alternatives you’ve considered We have tried supplying a set of hard redirects in next.config.js using “exportPathMap”, which works locally but not when deployed using the serverless-next.js component. We have considered adding another lambda@edge to the CloudFront inputs that can trim the slash before landing into the component’s routing logic, however that would increase latency. We have also considered just re-uploading the routing logic and altering the normaliseUri function to trim the trailing slash before the page manifest is searched by the uri, which is a wooden solution obviously (second to forking this project for altering that one function).

Thank you for any insight on this! Any stopgap ideas would be very appreciated as well.

Relevant pull request here https://github.com/serverless-nextjs/serverless-next.js/pull/448

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Reactions:2
  • Comments:15 (4 by maintainers)

github_iconTop GitHub Comments

3reactions
dphangcommented, Aug 31, 2020

This is available now (and various bugs should be fixed), please try out the latest alpha (1.17.0-alpha.9) and let us know if there are issues.

1reaction
lone-cloudcommented, Jul 2, 2020

My plan was to leave this one for you 😃

From what I see, it will not be copy/pasta of #448, but similar. This is the Next-side of the implementation for this task: https://github.com/vercel/next.js/pull/13333 The driving force for this feature will be whether the experimental.trailingSlash=true value is set in the deploying Next.js project’s next.config.js. As the lambdas are stateless, you will want to persist this configuration to the manifest.json (this is typed as OriginRequestDefaultHandlerManifest) - this will be done in lambda-at-edge/build.ts. The trailingSlash handling logic should live in the default lambda (default-handler.ts)… I’m undecided whether it’s needed for the api lambda too. Next.js handles the trailingSlash stuff using https://github.com/vercel/next.js/blob/canary/packages/next/client/normalize-trailing-slash.ts (there were some fixes since the original PR was released).

<div> GitHub</div><div>vercel/next.js</div><div>The React Framework. Contribute to vercel/next.js development by creating an account on GitHub.</div>
Read more comments on GitHub >

github_iconTop Results From Across the Web

add trailing slash to 404 url so it can be redirected
To do this add the following to the .htaccess file in the root directory of your site. Make sure these rules appear before...
Read more >
Trailing Slashes on URLs: Contentious or Settled?
Warning: GitHub Pages, Vercel, and Azure Static Web Apps all return a HTTP 404 error. I'll admit this one is a little more...
Read more >
Trailing slashes on root pages return 404 - - Bountysource
config.js using "exportPathMap", which works locally but not when deployed using the serverless-next.js component. We have considered adding another lambda@edge ...
Read more >
PI22830: 404 NOT FOUND ERROR GENERATED FOR ... - IBM
A 404 error is generated for a request without a trailing slash after the context root. It works fine with the trailing.
Read more >
Handling 404 Trailing Slash Error in NextJs | by Ayush Agarwal
What's the issue? Let's say you have a file named pages/shop/index. · The Solution (or a workaround). Since NextJs is only facing the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found