next-runtime icon indicating copy to clipboard operation
next-runtime copied to clipboard

[Bug]: Redirects are not working in the deployed application

Open lukasholzer opened this issue 2 years ago • 5 comments

Summary

When I create a app with netlify and add a _redirects file and serve it with ntl dev it's working on the deployed app it's not

Steps to reproduce

  1. Clone this repo: https://github.com/lukasholzer/netlify-next-redirect-issue
  2. Ntl dev (on the home page it should use the redirect)
  3. Check out the deployed version (not working) https://main--euphonious-swan-75085e.netlify.app/

The site: https://app.netlify.com/sites/euphonious-swan-75085e/overview

A link to a reproduction repository

https://github.com/lukasholzer/netlify-next-redirect-issue

Next Runtime version

should be the latest in the CI

More information about your build

  • [ ] I am building using the CLI
  • [ ] I am building using file-based configuration (netlify.toml)

What OS are you using?

Mac OS

Your netlify.toml file

`netlify.toml`
# Paste content of your `netlify.toml` file here

Your public/_redirects file

`_redirects`
/       /foo

Your next.config.js file

`next.config.js`
# Paste content of your `next.config.js` file here. Check there is no private info in there.

Builds logs (or link to your logs)

Build logs
# Paste logs here

Function logs

Function logs
# Paste logs here

.next JSON files

generated .next JSON files
# Paste file contents here. Please check there isn't any private info in them
# You can either build locally, or download the deploy from Netlify by clicking the arrow next to the deploy time.

lukasholzer avatar Jan 10 '23 16:01 lukasholzer

This is your answer 😁 https://app.netlify.com/sites/euphonious-swan-75085e/deploys/63bd91ffe5d0c10009779bc0#L227

ascorbic avatar Jan 10 '23 16:01 ascorbic

oh my gosh I just should have read that! but I think it's still strange that it's working in ntl dev and not in prod (provides a wrong safety feeling).

Especially If I move it to the public folder it's not working locally anymore with ntl dev

lukasholzer avatar Jan 11 '23 09:01 lukasholzer

Yeah, that has to be a bug. I wonder if dev is looking in the wrong publish dir

ascorbic avatar Jan 11 '23 09:01 ascorbic

~~@lukasholzer @ascorbic One thing to note, the docs mention a _rewrites and _headers should be moved to the /public folder, but it doesn't mention _redirects (potentially just a brain fart accidental renaming?)~~

~~The docs could of course be updated to say _redirects rather than _rewrites, but as mentioned, that doesn't seem to then make things work in dev.~~ (Note: docs updated in: https://github.com/netlify/next-runtime/pull/1895)

Similarly, this I believe potentially conflicts with NextJS's basePath config option, as since anything in public is hoisted to the basePath defined folder, we can seemingly never do something like redirect the root path ("/") to the base path, so the preview urls of https://your-subdomain-here.netlify.app will 404, and we need to manually go to https://your-subdomain-here.netlify.app/your-base-path-here

(Note: https://docs.netlify.com/integrations/frameworks/next-js/redirects-and-rewrites/ mentions to not add a root-level rewrite, but next.config.js redirects I believe won't catch on the root "/" if setup with a basePath config.)

scouttyg avatar Jan 18 '23 21:01 scouttyg

how do you guys solve this?, can't see the logs

oskarhertzman avatar Oct 05 '23 14:10 oskarhertzman

@ascorbic Is this still valid for v5?

serhalp avatar Jun 04 '24 15:06 serhalp