Skip to content

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

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

Closed
2 tasks
lukasholzer opened this issue Jan 10, 2023 · 6 comments
Closed
2 tasks

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

lukasholzer opened this issue Jan 10, 2023 · 6 comments
Labels
priority: medium status: awaiting user response type: bug code to address defects in shipped code v4 Issues related to the v4 Next.js runtime

Comments

@lukasholzer
Copy link
Contributor

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 lukasholzer added the type: bug code to address defects in shipped code label Jan 10, 2023
@ascorbic
Copy link
Contributor

@lukasholzer
Copy link
Contributor Author

lukasholzer commented Jan 11, 2023

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

@ascorbic
Copy link
Contributor

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

@scouttyg
Copy link

scouttyg commented Jan 18, 2023

@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: #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.)

@oskarhertzman
Copy link

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

@MarcL MarcL added v4 Issues related to the v4 Next.js runtime and removed Ecosystem: Frameworks labels Mar 13, 2024
@serhalp
Copy link
Member

serhalp commented Jun 4, 2024

@ascorbic Is this still valid for v5?

@serhalp serhalp closed this as not planned Won't fix, can't repro, duplicate, stale Jun 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
priority: medium status: awaiting user response type: bug code to address defects in shipped code v4 Issues related to the v4 Next.js runtime
Projects
None yet
Development

No branches or pull requests

7 participants